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",
|
"current_task",
|
||||||
"new_event_loop",
|
"new_event_loop",
|
||||||
"debug",
|
"debug",
|
||||||
"skip_after"
|
"skip_after",
|
||||||
]
|
]
|
||||||
|
|
|
@ -446,8 +446,9 @@ class AsyncScheduler:
|
||||||
# This is to ensure that even when tasks are
|
# This is to ensure that even when tasks are
|
||||||
# awaited instead of spawned, timeouts work as
|
# awaited instead of spawned, timeouts work as
|
||||||
# expected
|
# 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)
|
self.paused.discard(t)
|
||||||
|
print(t is self.current_task)
|
||||||
while self.paused and self.paused.get_closest_deadline() <= self.clock():
|
while self.paused and self.paused.get_closest_deadline() <= self.clock():
|
||||||
# Reschedules tasks when their deadline has elapsed
|
# Reschedules tasks when their deadline has elapsed
|
||||||
task = self.paused.get()
|
task = self.paused.get()
|
||||||
|
|
|
@ -59,6 +59,7 @@ class ResourceClosed(GiambioError):
|
||||||
Raised when I/O is attempted on a closed resource
|
Raised when I/O is attempted on a closed resource
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TooSlowError(GiambioError):
|
class TooSlowError(GiambioError):
|
||||||
"""
|
"""
|
||||||
This is raised if the timeout of a pool created using
|
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.current_task.next_deadline = mgr.timeout or 0.0
|
||||||
loop.deadlines.put(mgr)
|
loop.deadlines.put(mgr)
|
||||||
return mgr
|
return mgr
|
||||||
|
|
||||||
|
|
|
@ -63,4 +63,5 @@ class Queue:
|
||||||
|
|
||||||
self.events = {}
|
self.events = {}
|
||||||
|
|
||||||
|
|
||||||
# async def put
|
# async def put
|
||||||
|
|
|
@ -11,9 +11,11 @@ async def child(name: int):
|
||||||
async def main():
|
async def main():
|
||||||
start = giambio.clock()
|
start = giambio.clock()
|
||||||
try:
|
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, 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
|
await child(20) # Neither will this
|
||||||
except giambio.exceptions.TooSlowError:
|
except giambio.exceptions.TooSlowError:
|
||||||
print("[main] One or more children have timed out!")
|
print("[main] One or more children have timed out!")
|
||||||
|
@ -21,4 +23,4 @@ async def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
giambio.run(main, debugger=())
|
giambio.run(main, debugger=Debugger())
|
||||||
|
|
|
@ -12,7 +12,9 @@ async def main():
|
||||||
start = giambio.clock()
|
start = giambio.clock()
|
||||||
async with giambio.skip_after(10) as pool:
|
async with giambio.skip_after(10) as pool:
|
||||||
await pool.spawn(child, 7) # This will complete
|
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
|
await child(20) # Neither will this
|
||||||
if pool.timed_out:
|
if pool.timed_out:
|
||||||
print("[main] One or more children have timed out!")
|
print("[main] One or more children have timed out!")
|
||||||
|
|
Loading…
Reference in New Issue