Do not close fileno if GreenFileIO marked as closed

Fast-and-dirty attempt to fix issue #204
This commit is contained in:
Victor Sergeyev
2015-03-18 11:34:26 +02:00
parent 84b535beca
commit 06c450e872
2 changed files with 22 additions and 2 deletions

View File

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

View File

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