From 19d17982f392cea7b12b129676b9ac0fa0ed0684 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 24 Mar 2018 21:40:44 +0545 Subject: [PATCH] core: Split blocking and non-blocking Latch.get() Mostly just to avoid embarrassing function size, but it may come in useful for testing later. --- mitogen/core.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index aac73fa2..20add07b 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -943,7 +943,11 @@ class Latch(object): finally: self._lock.release() - _vv and IOLOG.debug('%r.get() -> sleeping', self) + return self._get_sleep(timeout, block) + + def _get_sleep(self, timeout, block): + _vv and IOLOG.debug('%r._get_sleep(timeout=%r, block=%r)', + self, timeout, block) e = None try: io_op(select.select, [_tls.rsock], [], [], timeout) @@ -954,10 +958,9 @@ class Latch(object): try: i = self._sleeping.index(_tls.wsock) del self._sleeping[i] - if i < self._waking: - self._waking -= 1 - else: + if i >= self._waking: raise TimeoutError() + self._waking -= 1 if _tls.rsock.recv(2) != '\x7f': raise LatchError('internal error: received >1 wakeups') if e: