Skip to content

Commit

Permalink
Merge pull request #14 from zopefoundation/fix-pipetrigger
Browse files Browse the repository at this point in the history
Fix pipetrigger.close() to close the right file descriptors
  • Loading branch information
mgedmin committed Nov 13, 2018
2 parents 1fcd856 + 47c5f3c commit 63f7863
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
4.0.2 (unreleased)
==================

- Fix pipetrigger.close() to close the right file descriptor.
(This could've been causing EBADF errors in unrelated places!)

- Add Python 3.7 support.


Expand Down
2 changes: 1 addition & 1 deletion src/zope/server/tests/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_thunk_error(self):
def thunk():
raise Exception("TestException")
t = self._makeOne()
t.close()
t.recv = lambda s: ''
t.thunks.append(thunk)
trigger.print = buf.write
try:
Expand Down
14 changes: 7 additions & 7 deletions src/zope/server/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class pipetrigger(_triggerbase, asyncore.file_dispatcher):

def __init__(self):
_triggerbase.__init__(self)
r, self.trigger = self._fds = os.pipe()
r, self.trigger = os.pipe()
asyncore.file_dispatcher.__init__(self, r)

if self.socket.fd != r:
Expand All @@ -154,12 +154,12 @@ def __init__(self):
os.close(r)

def _close(self):
for fd in self._fds:
try:
os.close(fd)
except OSError:
pass
self._fds = []
if self.socket is not None:
self.socket.close()
self.socket = None
if self.trigger is not None:
os.close(self.trigger)
self.trigger = None

def _physical_pull(self):
os.write(self.trigger, b'x')
Expand Down

0 comments on commit 63f7863

Please sign in to comment.