Subprocess Popen confusion
Peter Otten
__peter__ at web.de
Thu May 14 03:45:05 EDT 2020
Dick Holmes wrote:
> https://occovid19.ochealthinfo.com/coronavirus-in-oc
> I'm trying to
> communicate using a continuing dialog between two
> processes on the same system.
I think pexpect
https://pexpect.readthedocs.io/en/stable/index.html
does this naturally, but I don't know if Windows support is sufficient for
your needs.
> I've looked at various mechanisms and the
> class that seems to fit my needs is Popen in the subprocess module, but
> I can't seem to get more than a single round-trip message through Popen.
> I first call Popen then poll using the identifier returned from the call
> and the poll seems to work. I then call the communicate function passing
> None as the value to send to the companion process stdin. I get the
> expected result, but I also get "Exception condition detected on fd 0
> \\n" and "error detected on stdin\\n". Subsequent attempts to
> read/write/communicate with the subprocess fail because the file (stdxx
> PIPE) is closed.
>
> I can't tell from the documentation if the communicate function is a
> one-time operation.
Yes, communicate() is one-off,
"""Interact with process: Send data to stdin and close it.
Read data from stdout and stderr, until end-of-file is
reached. Wait for process to terminate.
...
"""
seems pretty clear. What would you improve?
> I have tried using read but the read call doesn't
> return (I'm using winpdb-reborn to monitor the operations).
Try readline(). Deadlocks may happen ;)
> I'm using Python 3.7, Windows 10, winpdb-reborn 2.0.0, rpdb2 1.5.0. If
> it makes any difference, I'm trying to communicate with GDB using the MI
> interpreter.
>
> Thoughts and advice appreciated!
>
> Dick
More information about the Python-list
mailing list