core: Split blocking and non-blocking Latch.get()

Mostly just to avoid embarrassing function size, but it may come in
useful for testing later.
pull/167/head
David Wilson 7 years ago
parent cba3347556
commit 19d17982f3

@ -943,7 +943,11 @@ class Latch(object):
finally: finally:
self._lock.release() 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 e = None
try: try:
io_op(select.select, [_tls.rsock], [], [], timeout) io_op(select.select, [_tls.rsock], [], [], timeout)
@ -954,10 +958,9 @@ class Latch(object):
try: try:
i = self._sleeping.index(_tls.wsock) i = self._sleeping.index(_tls.wsock)
del self._sleeping[i] del self._sleeping[i]
if i < self._waking: if i >= self._waking:
self._waking -= 1
else:
raise TimeoutError() raise TimeoutError()
self._waking -= 1
if _tls.rsock.recv(2) != '\x7f': if _tls.rsock.recv(2) != '\x7f':
raise LatchError('internal error: received >1 wakeups') raise LatchError('internal error: received >1 wakeups')
if e: if e:

Loading…
Cancel
Save