From 5f7633cd569f671750ea7f35f6ca79118b345205 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 18 Dec 2017 18:48:15 +0530 Subject: [PATCH] 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. --- mitogen/core.py | 5 +++++ mitogen/master.py | 1 + 2 files changed, 6 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index 2769021e..c6220d64 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -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 diff --git a/mitogen/master.py b/mitogen/master.py index 37829e41..2e30eaf4 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -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()