1

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?

jonsca
  • 10,218
  • 26
  • 54
  • 62

2 Answers2

1

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.

Community
  • 1
  • 1
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
0

have a look at subprocess module instead.

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143