From 06c450e87225923c3a89860d1777a6f9bad6cbdd Mon Sep 17 00:00:00 2001 From: Victor Sergeyev Date: Wed, 18 Mar 2015 11:34:26 +0200 Subject: [PATCH] Do not close fileno if GreenFileIO marked as closed Fast-and-dirty attempt to fix issue #204 --- eventlet/greenio/py3.py | 5 +++-- tests/subprocess_test.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/eventlet/greenio/py3.py b/eventlet/greenio/py3.py index e41663a..62208c0 100644 --- a/eventlet/greenio/py3.py +++ b/eventlet/greenio/py3.py @@ -126,9 +126,10 @@ class GreenFileIO(_OriginalIOBase): trampoline(self, write=True) def close(self): - _original_os.close(self._fileno) + if not self._closed: + _original_os.close(self._fileno) + self._closed = True notify_close(self._fileno) - self._closed = True for method in [ 'fileno', 'flush', 'isatty', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'tell', 'truncate', diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py index 2760eac..085f656 100644 --- a/tests/subprocess_test.py +++ b/tests/subprocess_test.py @@ -45,3 +45,22 @@ def test_communicate_with_poll(): eventlet.with_timeout(0.1, p.communicate, timeout_value=True) tdiff = time.time() - t1 assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time' + + +def test_close_popen_stdin_with_close_fds(): + p = subprocess.Popen( + ['ls'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + shell=False, + cwd=None, + env=None) + + p.communicate(None) + + try: + p.stdin.close() + except Exception as e: + assert False, "Exception should not be raised, got %r instead" % e