"""Construct and return tupel with IO objects:
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
"""
- if stdin == None and stdout == None and stderr == None:
+ if stdin is None and stdout is None and stderr is None:
return (None, None, None, None, None, None)
p2cread, p2cwrite = None, None
c2pread, c2pwrite = None, None
errread, errwrite = None, None
- if stdin == None:
+ if stdin is None:
p2cread = GetStdHandle(STD_INPUT_HANDLE)
elif stdin == PIPE:
p2cread, p2cwrite = CreatePipe(None, 0)
# Detach and turn into fd
p2cwrite = p2cwrite.Detach()
p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
- elif type(stdin) == int:
+ elif isinstance(stdin, int):
p2cread = msvcrt.get_osfhandle(stdin)
else:
# Assuming file-like object
p2cread = msvcrt.get_osfhandle(stdin.fileno())
p2cread = self._make_inheritable(p2cread)
- if stdout == None:
+ if stdout is None:
c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
elif stdout == PIPE:
c2pread, c2pwrite = CreatePipe(None, 0)
# Detach and turn into fd
c2pread = c2pread.Detach()
c2pread = msvcrt.open_osfhandle(c2pread, 0)
- elif type(stdout) == int:
+ elif isinstance(stdout, int):
c2pwrite = msvcrt.get_osfhandle(stdout)
else:
# Assuming file-like object
c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
c2pwrite = self._make_inheritable(c2pwrite)
- if stderr == None:
+ if stderr is None:
errwrite = GetStdHandle(STD_ERROR_HANDLE)
elif stderr == PIPE:
errread, errwrite = CreatePipe(None, 0)
errread = msvcrt.open_osfhandle(errread, 0)
elif stderr == STDOUT:
errwrite = c2pwrite
- elif type(stderr) == int:
+ elif isinstance(stderr, int):
errwrite = msvcrt.get_osfhandle(stderr)
else:
# Assuming file-like object
# Process startup details
default_startupinfo = STARTUPINFO()
- if startupinfo == None:
+ if startupinfo is None:
startupinfo = default_startupinfo
if not None in (p2cread, c2pwrite, errwrite):
startupinfo.dwFlags |= STARTF_USESTDHANDLES
# output pipe are maintained in this process or else the
# pipe will not close when the child process exits and the
# ReadFile will hang.
- if p2cread != None:
+ if p2cread is not None:
p2cread.Close()
- if c2pwrite != None:
+ if c2pwrite is not None:
c2pwrite.Close()
- if errwrite != None:
+ if errwrite is not None:
errwrite.Close()
def poll(self):
"""Check if child process has terminated. Returns returncode
attribute."""
- if self.returncode == None:
+ if self.returncode is None:
if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self)
def wait(self):
"""Wait for child process to terminate. Returns returncode
attribute."""
- if self.returncode == None:
+ if self.returncode is None:
obj = WaitForSingleObject(self._handle, INFINITE)
self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self)
stderr_thread.start()
if self.stdin:
- if input != None:
+ if input is not None:
self.stdin.write(input)
self.stdin.close()
stderr_thread.join()
# All data exchanged. Translate lists into strings.
- if stdout != None:
+ if stdout is not None:
stdout = stdout[0]
- if stderr != None:
+ if stderr is not None:
stderr = stderr[0]
# Translate newlines, if requested. We cannot let the file
c2pread, c2pwrite = None, None
errread, errwrite = None, None
- if stdin == None:
+ if stdin is None:
pass
elif stdin == PIPE:
p2cread, p2cwrite = os.pipe()
- elif type(stdin) == int:
+ elif isinstance(stdin, int):
p2cread = stdin
else:
# Assuming file-like object
p2cread = stdin.fileno()
- if stdout == None:
+ if stdout is None:
pass
elif stdout == PIPE:
c2pread, c2pwrite = os.pipe()
- elif type(stdout) == int:
+ elif isinstance(stdout, int):
c2pwrite = stdout
else:
# Assuming file-like object
c2pwrite = stdout.fileno()
- if stderr == None:
+ if stderr is None:
pass
elif stderr == PIPE:
errread, errwrite = os.pipe()
elif stderr == STDOUT:
errwrite = c2pwrite
- elif type(stderr) == int:
+ elif isinstance(stderr, int):
errwrite = stderr
else:
# Assuming file-like object
if shell:
args = ["/bin/sh", "-c"] + args
- if executable == None:
+ if executable is None:
executable = args[0]
# For transferring possible exec failure from child to parent
if close_fds:
self._close_fds(but=errpipe_write)
- if cwd != None:
+ if cwd is not None:
os.chdir(cwd)
if preexec_fn:
apply(preexec_fn)
- if env == None:
+ if env is None:
os.execvp(executable, args)
else:
os.execvpe(executable, args, env)
def poll(self):
"""Check if child process has terminated. Returns returncode
attribute."""
- if self.returncode == None:
+ if self.returncode is None:
try:
pid, sts = os.waitpid(self.pid, os.WNOHANG)
if pid == self.pid:
def wait(self):
"""Wait for child process to terminate. Returns returncode
attribute."""
- if self.returncode == None:
+ if self.returncode is None:
pid, sts = os.waitpid(self.pid, 0)
self._handle_exitstatus(sts)
return self.returncode
stderr.append(data)
# All data exchanged. Translate lists into strings.
- if stdout != None:
+ if stdout is not None:
stdout = ''.join(stdout)
- if stderr != None:
+ if stderr is not None:
stderr = ''.join(stderr)
# Translate newlines, if requested. We cannot let the file