I have a queue with threading setup. I need it to kill the process if it runs longer than 2900s which works fine. I'm wanting to write out information if it has to kill the process because it ran to long. Is there a way to write a custom function for this line:
timer = Timer(2900, recover.kill)
to:
timer = Timer(2900, custom_function(recover))
Where I can run custom_function to do stuff before calling recover.kill? I tried doing this but it doesn't work.
while not q.empty():
try:
cmd = "itf -obj " + q.get()
recover = subprocess.Popen(shlex.split(cmd), env=my_env, shell=False)
timer = Timer(2900, recover.kill)
try:
timer.start()
my_pid, err = recover.communicate()
recover.wait()
q.task_done()
finally:
print("Completed before time")
timer.cancel()
except Exception as e:
q.task_done()
continue
Thanks!