Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with suppress(asyncio.CancelledError):
await self.read_loop_task
if self.pending or (self.pending_specials and self.pending_specials != {None: []}):
log.warning('Pendings: {}; specials: {}'.format(self.pending, self.pending_specials))
try:
# await list(pending_with_timeouts)
self.abort(exception=exc.TimeoutError)
# wlist = list(self.drain_all_pending())
# log.warning('Wait for list: {} {}'.format(wlist, self.pending))
# if len(wlist) > 0:
# await asyncio.wait(wlist, timeout=timeout)
except asyncio.TimeoutError:
log.warning('ABORT Timeout')
await self.abort(exception=exc.TimeoutError)
except Exception as e:
log.exception('in close: {}'.format(e))
raise e
finally:
log.debug('Closing writer')
self.writer.close()
log.debug('Writer closed')
async def close(self, timeout):
if self.closing:
return
self.closing = True
if self.read_loop_task:
self.read_loop_task.cancel()
with suppress(asyncio.CancelledError):
await self.read_loop_task
if self.pending or (self.pending_specials and self.pending_specials != {None: []}):
log.warning('Pendings: {}; specials: {}'.format(self.pending, self.pending_specials))
try:
# await list(pending_with_timeouts)
self.abort(exception=exc.TimeoutError)
# wlist = list(self.drain_all_pending())
# log.warning('Wait for list: {} {}'.format(wlist, self.pending))
# if len(wlist) > 0:
# await asyncio.wait(wlist, timeout=timeout)
except asyncio.TimeoutError:
log.warning('ABORT Timeout')
await self.abort(exception=exc.TimeoutError)
except Exception as e:
log.exception('in close: {}'.format(e))
raise e
finally:
log.debug('Closing writer')
self.writer.close()
log.debug('Writer closed')
async def wait(self, timeout=None):
barrier_lifted = self.client.wait_for_events(
[WatchEvent.DELETED], self.path
)
exists = await self.client.exists(path=self.path, watch=True)
if not exists:
return
try:
if timeout:
await asyncio.wait_for(barrier_lifted, timeout)
else:
await barrier_lifted
except asyncio.TimeoutError:
raise exc.TimeoutError
path = self.sibling_path(sibling)
unblocked = self.client.wait_for_events([WatchEvent.DELETED], path)
exists = await self.client.exists(path=path, watch=True)
if not exists:
unblocked.set_result(None)
try:
if timeout:
await asyncio.wait_for(unblocked, timeout)
else:
await unblocked
except asyncio.TimeoutError:
raise exc.TimeoutError
_, participants = await self.analyze_siblings()
if exists:
return
elif len(participants) >= self.min_participants:
await self.create_znode(self.sentinel_path)
return
try:
if timeout:
await asyncio.wait_for(barrier_lifted, timeout)
else:
await barrier_lifted
except asyncio.TimeoutError:
raise exc.TimeoutError
async def wait_in_line(self, znode_label, timeout=None, blocked_by=None):
time_limit = None
if timeout is not None:
time_limit = time.time() + timeout
await self.create_unique_znode(znode_label)
while True:
if time_limit and time.time() >= time_limit:
await self.delete_unique_znode(znode_label)
raise exc.TimeoutError
owned_positions, contenders = await self.analyze_siblings()
if znode_label not in owned_positions:
raise exc.SessionLost
blockers = contenders[:owned_positions[znode_label]]
if blocked_by:
blockers = [
contender for contender in blockers
if self.determine_znode_label(contender) in blocked_by
]
if not blockers:
break
try: