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:
parent
549942344e
commit
5f7633cd56
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue