|
|
@ -78,7 +78,7 @@ else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Error(Exception):
|
|
|
|
class Error(Exception):
|
|
|
|
def __init__(self, fmt, *args):
|
|
|
|
def __init__(self, fmt=None, *args):
|
|
|
|
if args:
|
|
|
|
if args:
|
|
|
|
fmt %= args
|
|
|
|
fmt %= args
|
|
|
|
Exception.__init__(self, fmt)
|
|
|
|
Exception.__init__(self, fmt)
|
|
|
@ -113,7 +113,7 @@ class StreamError(Error):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimeoutError(StreamError):
|
|
|
|
class TimeoutError(Error):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -805,22 +805,23 @@ class Latch(object):
|
|
|
|
if self.queue:
|
|
|
|
if self.queue:
|
|
|
|
return self.queue.pop(0)
|
|
|
|
return self.queue.pop(0)
|
|
|
|
if not block:
|
|
|
|
if not block:
|
|
|
|
return
|
|
|
|
raise TimeoutError()
|
|
|
|
self._tls_init()
|
|
|
|
self._tls_init()
|
|
|
|
self.wake_socks.append(_tls.wsock)
|
|
|
|
self.wake_socks.append(_tls.wsock)
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
self.lock.release()
|
|
|
|
self.lock.release()
|
|
|
|
|
|
|
|
|
|
|
|
rfds, _, _ = select.select([_tls.rsock], [], [], timeout)
|
|
|
|
rfds, _, _ = select.select([_tls.rsock], [], [], timeout)
|
|
|
|
assert len(rfds) or timeout is None
|
|
|
|
assert len(rfds) or timeout is not None
|
|
|
|
|
|
|
|
|
|
|
|
self.lock.acquire()
|
|
|
|
self.lock.acquire()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if _tls.wsock in self.wake_socks:
|
|
|
|
if _tls.wsock in self.wake_socks:
|
|
|
|
# Nothing woke us, remove stale entry.
|
|
|
|
# Nothing woke us, remove stale entry.
|
|
|
|
self.wake_socks.remove(_tls.wsock)
|
|
|
|
self.wake_socks.remove(_tls.wsock)
|
|
|
|
return
|
|
|
|
raise TimeoutError()
|
|
|
|
if _tls.rsock in rfds:
|
|
|
|
|
|
|
|
|
|
|
|
assert _tls.rsock in rfds
|
|
|
|
_tls.rsock.recv(1)
|
|
|
|
_tls.rsock.recv(1)
|
|
|
|
return self.queue.pop(0)
|
|
|
|
return self.queue.pop(0)
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|