subprocess - create background process with Python's Popen -


i'm new bie python. recently, face problem python popen, , hope can me. :d

a.py

#!/usr/bin/env python import b  b.run() while true:      pass 

b.py

#!/usr/bin/env python                                                                                                                                                                       import subprocess  def run():     subprocess.popen(['ping www.google.com > /dev/null &'], shell=true)  run() 

when run b.py , grep process status

$ ps aux | grep  test 35806 0.0  0.0  2451284 592 s010  sl  10:11 0:00.00 ping www.google.com 

the ping process runs in background state sl.

and try run a.py

$ ps aux | grep  test 36088 0.0  0.0  2444116 604 s010  sl+ 10:15 0:00.00 ping www.google.com 

ping process state changes sl+, , if stop a.py ctrl + c, ping process terminated.

is there way make ping process run in backgroud, , not affected when stop a.py? , why ping process state changes sl sl+?

after research, found can add "preexec_fn=os.setsid", , solve problem.

subprocess.popen(['ping www.google.com > /dev/null &'], shell=true, preexec_fn=os.setsid) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -