From 2c22c418199d6b5e8d005250c28f26f70b21ce5d Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 20 Mar 2018 13:01:26 +0545 Subject: [PATCH] issue #156: don't decrement `waking` if we timed out rather than being woken. --- docs/howitworks.rst | 6 +++--- mitogen/core.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/howitworks.rst b/docs/howitworks.rst index 4710b2f4..ec736758 100644 --- a/docs/howitworks.rst +++ b/docs/howitworks.rst @@ -925,9 +925,9 @@ item. :py:meth:`mitogen.core.Latch.put`. **4. Wake, Non-empty** - On wake it re-acquires `lock`, removes itself from `sleeping`, decrementing - `waking`, throws :py:class:`mitogen.core.TimeoutError` if no byte was - written, otherwise pops and returns the first item in `queue` that is + On wake it re-acquires `lock`, removes itself from `sleeping`, throws + :py:class:`mitogen.core.TimeoutError` if no byte was written, decrements + `waking`, then pops and returns the first item in `queue` that is guaranteed to exist. diff --git a/mitogen/core.py b/mitogen/core.py index b9dd1488..7617be26 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -957,11 +957,11 @@ class Latch(object): self._lock.acquire() try: self._sleeping.remove(_tls.wsock) - self._waking -= 1 if self.closed: raise LatchError() if not rfds: raise TimeoutError() + self._waking -= 1 if _tls.rsock.recv(2) != '\x7f': raise LatchError('internal error: received >1 wakeups') try: