mirror of https://github.com/nocturn9x/giambio.git
Fixed bug with sleeping from the main task
This commit is contained in:
parent
89501eb7b2
commit
4e1d328df4
|
@ -41,5 +41,5 @@ __all__ = [
|
|||
"current_task",
|
||||
"new_event_loop",
|
||||
"debug",
|
||||
"skip_after"
|
||||
"skip_after",
|
||||
]
|
||||
|
|
|
@ -422,9 +422,9 @@ class AsyncScheduler:
|
|||
pool.timed_out = True
|
||||
for task in pool.tasks:
|
||||
if not task.done():
|
||||
self.paused.discard(task)
|
||||
self.io_release_task(task)
|
||||
task.throw(TooSlowError(task))
|
||||
self.paused.discard(task)
|
||||
self.io_release_task(task)
|
||||
task.throw(TooSlowError(task))
|
||||
|
||||
def schedule_tasks(self, tasks: List[Task]):
|
||||
"""
|
||||
|
@ -446,8 +446,9 @@ class AsyncScheduler:
|
|||
# This is to ensure that even when tasks are
|
||||
# awaited instead of spawned, timeouts work as
|
||||
# expected
|
||||
if t.done() or t in self.run_ready or t is self.current_task:
|
||||
if t.done() or t in self.run_ready:
|
||||
self.paused.discard(t)
|
||||
print(t is self.current_task)
|
||||
while self.paused and self.paused.get_closest_deadline() <= self.clock():
|
||||
# Reschedules tasks when their deadline has elapsed
|
||||
task = self.paused.get()
|
||||
|
@ -598,7 +599,7 @@ class AsyncScheduler:
|
|||
"""
|
||||
|
||||
if task.pool and task.pool.enclosed_pool and not task.pool.enclosed_pool.done():
|
||||
return
|
||||
return
|
||||
for t in task.joiners:
|
||||
if t not in self.run_ready:
|
||||
# Since a task can be the parent
|
||||
|
|
|
@ -59,6 +59,7 @@ class ResourceClosed(GiambioError):
|
|||
Raised when I/O is attempted on a closed resource
|
||||
"""
|
||||
|
||||
|
||||
class TooSlowError(GiambioError):
|
||||
"""
|
||||
This is raised if the timeout of a pool created using
|
||||
|
|
|
@ -127,4 +127,3 @@ def skip_after(timeout: int or float):
|
|||
loop.current_task.next_deadline = mgr.timeout or 0.0
|
||||
loop.deadlines.put(mgr)
|
||||
return mgr
|
||||
|
||||
|
|
|
@ -63,4 +63,5 @@ class Queue:
|
|||
|
||||
self.events = {}
|
||||
|
||||
|
||||
# async def put
|
||||
|
|
|
@ -11,9 +11,11 @@ async def child(name: int):
|
|||
async def main():
|
||||
start = giambio.clock()
|
||||
try:
|
||||
async with giambio.with_timeout(10) as pool:
|
||||
async with giambio.with_timeout(12) as pool:
|
||||
await pool.spawn(child, 7) # This will complete
|
||||
await pool.spawn(child, 15) # This will not
|
||||
await giambio.sleep(2) # This will make the code below wait 2 seconds
|
||||
await pool.spawn(child, 15) # This will not complete
|
||||
await giambio.sleep(50)
|
||||
await child(20) # Neither will this
|
||||
except giambio.exceptions.TooSlowError:
|
||||
print("[main] One or more children have timed out!")
|
||||
|
@ -21,4 +23,4 @@ async def main():
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
giambio.run(main, debugger=())
|
||||
giambio.run(main, debugger=Debugger())
|
||||
|
|
|
@ -12,7 +12,9 @@ async def main():
|
|||
start = giambio.clock()
|
||||
async with giambio.skip_after(10) as pool:
|
||||
await pool.spawn(child, 7) # This will complete
|
||||
await pool.spawn(child, 15) # This will not
|
||||
await giambio.sleep(2) # This will make the code below wait 2 seconds
|
||||
await pool.spawn(child, 15) # This will not complete
|
||||
await giambio.sleep(50)
|
||||
await child(20) # Neither will this
|
||||
if pool.timed_out:
|
||||
print("[main] One or more children have timed out!")
|
||||
|
|
Loading…
Reference in New Issue