patcher: certain order of import subprocess and monkey_patch breaks .communicate()

https://github.com/eventlet/eventlet/issues/290
This commit is contained in:
Sergey Shepelev
2016-01-24 23:27:52 +05:00
parent a79c0ee57a
commit 8ea9df6b9f
4 changed files with 31 additions and 4 deletions

View File

@@ -6,7 +6,9 @@ from eventlet.support import six
__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):

View File

@@ -9,7 +9,9 @@ if __name__ == '__main__':
# * 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

View File

@@ -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')

View File

@@ -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')
@@ -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')