I find the documentation on Popen.communicate()
somewhat incomplete. Take the example from the documentation, with a slight modification:
p = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
try :
outs, errs = p.communicate(ins, timeout=5)
except TimeoutExpired:
p.kill()
outs, errs = p.communicate(ins) # What's with the input data?
# What value does p.returncode have at this point?
Then I have two questions:
- If I send input
ins
to the child process, do I resend the input after catching the timeout exception? Does this handle already read input correctly? - What will be the value (if any) of
p.returncode
after callingp.kill()
, i.e. after sending aSIGKILL
to the process?