- def setup():
- # runs in the child process
- if not rhost:
- os.environ['PATH'] = ':'.join([nicedir,
- os.environ.get('PATH', '')])
- os.setsid()
- return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- preexec_fn=setup)
+ if rhost:
+ env = environ
+ else:
+ envpath = environ.get(b'PATH')
+ env = environ.copy()
+ env[b'PATH'] = nicedir if not envpath else nicedir + b':' + envpath
+ if sys.version_info[0] < 3:
+ return subprocess.Popen(argv,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=stderr,
+ env=env,
+ preexec_fn=lambda: os.setsid())
+ else:
+ return subprocess.Popen(argv,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=stderr,
+ env=env,
+ start_new_session=True)