开发者

Python interpreter waits for child process to die

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜