Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does subprocess.communicate() close stdin after writing input to it?

While it would seem logical, the documentation does not explicitly state it:

Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate.

like image 804
static_rtti Avatar asked Oct 17 '25 09:10

static_rtti


1 Answers

From looking at the source I think the answer is yes:

  • when timeout is None, communicate() calls self._stdin_write(input)
    https://github.com/python/cpython/blob/master/Lib/subprocess.py#L826-L827

  • otherwise _communicate() calls self._stdin_write(input)
    https://github.com/python/cpython/blob/master/Lib/subprocess.py#L1078-L1079

  • in each case _stdin_write() calls self.stdin.close() after self.stdin.write(input)
    https://github.com/python/cpython/blob/master/Lib/subprocess.py#L793

like image 163
jq170727 Avatar answered Oct 19 '25 01:10

jq170727



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!