I'm trying to write a scheduler script for slurm jobs in python.
Basically, I have a script contained in a function,let's call it job_array_scheduler()
, that contains a time.sleep()
loop. This is expected to run for a day or more. I want to be able to start this function off as a separate thread from inside python, such that I can then exit the session and this thing will keep running.
I tried doing it like so:
import threading
scheduler_thread = threading.Thread(target=job_array_scheduler, args=args, daemon=True)
scheduler_thread.start()
but this exits when I exit the python session (i.e just with exit
).
How to I get around this, to keep the above thread alive so I can exit the python session or even log my user off?
The only way I can think of is writing another script to wrap around the above, so I can run it in the background from the shell doing something like python wrapper_script.py &
but I would prefer to avoid that as I would have to write a separate outer script for each such job I want to do.