Reputation: 13
Contents of check.py
:
from multiprocessing import Process
import time
import sys
def slp():
time.sleep(30)
f=open("yeah.txt","w")
f.close()
if __name__=="__main__" :
x=Process(target=slp)
x.start()
sys.exit()
In windows 7, from cmd
, if I call python check.py
, it doesn't immediately exit, but instead waits for 30 seconds. And if I kill cmd
, the child dies too- no "yeah.txt"
is created.
How do I make ensure the child continues to run even if parent is killed and also that the parent doesn't wait for child process to end?
Upvotes: 1
Views: 617
Reputation: 57691
What you seem to want is running your script as a background process. The solution in How to start a background process in Python? should do, you will have to specify some command line parameter that tell your script to go into slp
rather than spawning a new process.
Upvotes: 1