How to Terminate a Python program before its child is finished running? -


i have script supposed run 24/7 unless interrupted. script script a. want script call script b, , have script exit while b running. possible? thought work

#script_a.py while(1)     stuff     more stuff     if true:         os.system("python script_b.py")         sys.exit(0)   #script_b.py time.sleep(some_time) os.system("python script_a.py") sys.exit(0) 

but seems if doesn't exit until b has finished executing (which not want happen). there way this?

what describing sounds lot function call:

def doscriptb():   # stuff   # more stuff  def doscripta():   while true:     # stuff     if condition:       doscriptb()       return  while true:   doscripta() 

if insufficient you, have detach process python process. involves spawning process in background, done appending ampersand command in bash:

yes 'this background process' & 

and detaching said process current shell, which, in simple c program done forking process twice. don't know how in python, bet, there module this.

this way, when calling python process exits, won't terminate spawned child, since independent.


Comments