New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subprocess.Popen.communicate(...) hangs on Windows #52877
Comments
After using subprocess.Popen(...).communicate(), the session hangs. c:\>python31
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>> Popen(["echo","Hello!"], stdout=PIPE).communicate()[0]
b'Hello!\n'
>>> At this point, the session stops responding to keyboard input. ========================================= Neither Ctrl-C, Ctrl-Z, nor Ctrl-D will break out of it, but Ctrl-Break does break out of it. The task manager shows no CPU activity for the process. I've seen problem with Python v3.1.2 and v2.6.1 on Windows 7. It works fine under Linux: $ python3.1
Python 3.1 (r31:73572, Mar 22 2010, 14:57:00)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>> Popen(["echo","Hello!"], stdout=PIPE).communicate()[0]
b'Hello!\n'
>>> print("No problems under Linux")
No problems under Linux
>>> Is this bug type "crash" or "behavior"? I went with the former, since it ends the usable Python session. |
I can't reproduce this using Windows Vista. |
I can't reproduce on W7. Strangely, though, although my banner suggests that I have exactly the same build as you, I get a "\r\n" at the end of the communicate bytestream, not a simple "\n" as you're getting. Do you have any environment variables or Python command-line switches which might be affecting anything? Could you try with python31/26 -E -S just in case, please? |
I am on Windows 7. I realized the "echo" command I'm piping to belongs to Cygwin. I'll try to make a different example to either support this, or otherwise close the bug. Thanks! |
I'm with Tim and Mark - can't reproduce this, so I'm closing the report. If you are able to find another case which can reproduce this, feel free to re-open. |
I can reproduce this on WinXP with 2.5, 2.7 and 3.2. On my other box (Win7 64bit) the same code works without problems. After entering the following python does not respond to any input:
>>> import subprocess
>>> subprocess.call('echo') |
There are certainly some problems with subprocess on Windows.
Note .../python34> pip pyflakes installs in a second or two.
...> pyflakes -h # Windows Command Propmpt WCP
>>> import subprocess as s; s.check_output("pyflakes -h")
console interpreter CI or Idle, all produce help output WCP> pyflakes c:\programs\python34\lib\turtle.py # or / instead of \ CI>>> s.check_output("pyflakes c:\programs\python34\lib\turtle.py")
pause, so almost think is hanging, then c:\programs\python34\lib\lib2to3\tests\data\bom.py:2:17: invalid syntax print "BOM BOOM!" ID>>> s.check_output("pyflakes c:\programs\python34\lib\turtle.py")
hangs indefinitely, no output
CI or ID >>> s.check_output("pyflakes c:/programs/python34/lib/turtle.py") # / instead of \ which was ok in WCP
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\Python\dev\5\py35\lib\subprocess.py", line 627, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'pyflakes c:/programs/python34/lib/turtle
.py' returned non-zero exit status 1 Above is CI 3.5 and Idle 3.4. subprocess and pyflakes work fine on linux. We are trying to add a feature to Idle to do above on file in editor, and are stuck here. The actual provisional code is |
It might be unrelated to the issue but "\t" is a tab; a raw-string literal should be used instead: >>> from subprocess import check_output |
That has been pointed out to me. I need to repost with the results after correcting the commands (there is still a problem). |
I can't reproduce either on 2.7 or on 3.5 with any of the examples shown. Closing again as not-a-bug. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: