0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3: 一定間隔の処理

Posted at

こちらの記事を参考にしました。
Python3で一定間隔で処理を行う

プログラム

0.25 sec 毎に実行

signal01.py
#! /usr/bin/python
#
#	signal01.py
#
#						Jun/08/2025
#
import signal
import time
    
def scheduler(arg1, args2):
	end = time.time() 
	time_diff = end - start 
	print(time_diff)

duration = 0.25
start = time.time() 
signal.signal(signal.SIGALRM, scheduler)
signal.setitimer(signal.ITIMER_REAL, duration, duration)

time.sleep(5000)

実行結果

$ ./signal01.py 
0.25015687942504883
0.5001039505004883
0.7502927780151367
1.0001683235168457
1.250462532043457
1.5001108646392822
1.7501001358032227
2.0001344680786133
2.25012469291687
2.5001094341278076
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?