Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Popen returns pipes that don't support O_NONBLOCK #222
Popen from the gevent subprocess module returns pipes that don't support non-blocking mode. The following example demonstrates the problem:
import sys, os, fcntl, subprocess, select from gevent import monkey monkey.patch_all(subprocess=False) p = subprocess.Popen([sys.executable, '-c', 'import time,sys;print "test";sys.stdout.flush();time.sleep(10)'], stdout=subprocess.PIPE) fcntl.fcntl(p.stdout, fcntl.F_SETFL, os.O_NONBLOCK) select.select([p.stdout], , ) print p.stdout.read(1024)
Without monkey patching subprocess the code doesn't block, removing subprocess=False causes it to block. The reason is that p.stdout is a FileObjectPosix object instead of a normal File object and calling fcntl on the FileObjectPosix object doesn't really change anything: the underlying file descriptor is already non-blocking.
I don't really know what the right way to fix this is. We could add support for non-blocking I/O to FileObjectPosix, but that doesn't seem easy. The other option would be to change Popen to return normal File objects instead of FileObjectPosix objects.
The implementation has changed substantially since this was written, but the basic issue remains. I've added clarifying remarks to the documentation, to wit:
A workaround is to use