I would like to run a project (project.py) that has two scheduling elements like this answer I found on stack overflow: Periodically execute function in thread in real time, every N seconds
One function is to run every x
seconds the other every y
seconds
where 0.03 < x < 0.1
and 2 < y < 10
.
function_x(t)
calls an outside program (sync.py) that pauses (SIGSTOP
) project.py
Question 0: After calling do_every, the program continues it's execution. Is this a correct assumption?
Question 1: If sync.py takes 2 seconds to execute before calling SIGCONT
on project.py, will function_x
's Timer be 'messed up'?
Question 3: If function_y
is sending data over a socket, will function_x
calling SIGSTOP
mess up this execution? Will the timing be paused? How does the timer count time?
Answer referenced earlier:
import threading;
def do_every (interval, worker_func, iterations = 0):
if iterations != 1:
threading.Timer (
interval,
do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1]
).start ();
worker_func ();
def print_hw ():
print "hello world";
def print_so ():
print "stackoverflow"
# call print_so every second, 5 times total
do_every (1, print_so, 5);
# call print_hw two times per second, forever
do_every (0.5, print_hw);