More I/O fixes
This commit is contained in:
parent
e423716442
commit
dd924d600c
|
@ -58,6 +58,8 @@ class TaskScope:
|
||||||
if not self.entry_point.done():
|
if not self.entry_point.done():
|
||||||
self.timed_out = True
|
self.timed_out = True
|
||||||
await throw(self.entry_point, TimeoutError("timed out"))
|
await throw(self.entry_point, TimeoutError("timed out"))
|
||||||
|
# Wait for the parent to exit or cancel us
|
||||||
|
await wait(self.entry_point)
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self.entry_point = await current_task()
|
self.entry_point = await current_task()
|
||||||
|
@ -67,13 +69,13 @@ class TaskScope:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def __aexit__(self, exc_type: type, exception: Exception, tb):
|
async def __aexit__(self, exc_type: type, exception: Exception, tb):
|
||||||
await close_scope(self)
|
|
||||||
if self.timeout and not self.waiter.done():
|
if self.timeout and not self.waiter.done():
|
||||||
# Well, looks like we finished before our worker.
|
# Well, looks like we finished before our worker.
|
||||||
# Thanks for your help! Now die.
|
# Thanks for your help! Now die.
|
||||||
self.timeout_scope.cancellable = True
|
self.timeout_scope.cancellable = True
|
||||||
await cancel(self.waiter, block=True)
|
await cancel(self.waiter, block=True)
|
||||||
# Task scopes are sick: Nathaniel, you're an effing genius.
|
# Task scopes are sick: Nathaniel, you're an effing genius.
|
||||||
|
await close_scope(self)
|
||||||
if isinstance(exception, TimeoutError) and self.timed_out:
|
if isinstance(exception, TimeoutError) and self.timed_out:
|
||||||
# This way we only silence our own timeouts and not
|
# This way we only silence our own timeouts and not
|
||||||
# someone else's!
|
# someone else's!
|
||||||
|
|
Reference in New Issue