master: make mitogen minimally functional under gevent

It seems gevent automatically sets blocking behaviour on fds produced by
the socket module, which causes the Python process we fork to fail
horribly. So in the child, always reset the blocking flag.
This commit is contained in:
David Wilson 2017-12-18 18:48:15 +05:30
parent 549942344e
commit 5f7633cd56
2 changed files with 6 additions and 0 deletions

View File

@ -162,6 +162,11 @@ def set_nonblock(fd):
fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def set_block(fd):
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)
def io_op(func, *args):
try:
return func(*args), False

View File

@ -102,6 +102,7 @@ def create_child(*args):
parentfp, childfp = socket.socketpair()
pid = os.fork()
if not pid:
mitogen.core.set_block(childfp.fileno())
os.dup2(childfp.fileno(), 0)
os.dup2(childfp.fileno(), 1)
childfp.close()