Skip to content

Commit

Permalink
patcher: certain order of import subprocess and monkey_patch breaks .…
Browse files Browse the repository at this point in the history
…communicate()

#290
  • Loading branch information
temoto committed Jan 24, 2016
1 parent a79c0ee commit 8ea9df6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion eventlet/green/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


__patched__ = ['select']
__deleted__ = ['devpoll', 'poll', 'epoll', 'kqueue', 'kevent']
# FIXME: must also delete `poll`, but it breaks subprocess `communicate()`
# https://github.com/eventlet/eventlet/issues/290
__deleted__ = ['devpoll', 'epoll', 'kqueue', 'kevent']


def get_fileno(obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# * https://bitbucket.org/eventlet/eventlet/issues/167
# * https://github.com/eventlet/eventlet/issues/169
import select
for name in ['devpoll', 'poll', 'epoll', 'kqueue', 'kevent']:
# FIXME: must also delete `poll`, but it breaks subprocess `communicate()`
# https://github.com/eventlet/eventlet/issues/290
for name in ['devpoll', 'epoll', 'kqueue', 'kevent']:
assert not hasattr(select, name), name

import sys
Expand Down
13 changes: 13 additions & 0 deletions tests/isolated/subprocess_patched_communicate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# no standard tests in this file, ignore
__test__ = False


if __name__ == '__main__':
import sys
import eventlet
import subprocess
eventlet.monkey_patch(all=True)
p = subprocess.Popen([sys.executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()

print('pass')
14 changes: 12 additions & 2 deletions tests/subprocess_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
import time

import eventlet
from eventlet.green import subprocess
import eventlet.patcher
import sys
import time
import tests
original_subprocess = eventlet.patcher.original('subprocess')


Expand Down Expand Up @@ -73,3 +75,11 @@ def test_universal_lines():
stdout=subprocess.PIPE,
universal_newlines=True)
p.communicate(None)


def test_patched_communicate_290():
# https://github.com/eventlet/eventlet/issues/290
# Certain order of import and monkey_patch breaks subprocess communicate()
# with AttributeError module `select` has no `poll` on Linux
# unpatched methods are removed for safety reasons in commit f63165c0e3
tests.run_isolated('subprocess_patched_communicate.py')

0 comments on commit 8ea9df6

Please sign in to comment.