开发者

Python interpreter waits for child process to die

开发者 https://www.devze.com 2023-03-14 21:01 出处:网络
Contents of check.py: from mu开发者_运维技巧ltiprocessing import Process import time import sys def slp():

Contents of check.py:

from mu开发者_运维技巧ltiprocessing 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?


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.


have a look at subprocess module instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号