Skip to content

Instantly share code, notes, and snippets.

@nobonobo
Created June 13, 2013 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobonobo/5772386 to your computer and use it in GitHub Desktop.
Save nobonobo/5772386 to your computer and use it in GitHub Desktop.
subprocessで子プロセス起こすとき、「, close_fds=True, preexec_fn=os.setsid」つけるとプロセスグループが独立するみたい。
# encoding: utf-8
import os
import signal
from subprocess import Popen
cmd = ['python', '-c', 'import time; time.sleep(1); print "Hello."']
if 0:
proc = Popen(cmd, close_fds=True, preexec_fn=os.setsid)
else:
proc = Popen(cmd)
os.killpg(os.getpgid(os.getpid()), signal.SIGTERM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment