Minor changes

This commit is contained in:
Mattia Giambirtone 2023-06-01 20:33:09 +02:00
parent bc60572c31
commit f4ac001f49
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
4 changed files with 12 additions and 8 deletions

View File

@ -74,7 +74,7 @@ class Queue:
# Stores event objects for tasks wanting to
# put items on the queue
self.putters: deque[Event] = deque()
self.container: deque[Event] = deque()
self.container: deque = deque()
def __len__(self):
"""
@ -84,7 +84,7 @@ class Queue:
return len(self.container)
def __repr__(self) -> str:
return f"{type(self).__name__}({f', '.join(map(str, self.container))})"
return f"{self.__class__.__name__}({f', '.join(map(str, self.container))})"
async def __aiter__(self):
"""

View File

@ -41,5 +41,6 @@ async def main_nested(n, o, p):
print(f"[main] Parent exited in {structio.clock() - t:.2f} seconds")
# Should take about 4 seconds
structio.run(main_simple, 5, 2, 2)
structio.run(main_nested, 5, 2, 2)

View File

@ -34,6 +34,9 @@ async def main_cancel(i, j):
p.spawn(canceller, s, i)
await structio.sleep(j)
print("[main] Canceling scope")
# Shields only protect from indirect cancellations
# coming from outer scopes: they are still cancellable
# explicitly!
s.cancel()
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")

View File

@ -16,7 +16,7 @@ async def main_cancel(i):
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
async def main_wait_successful():
async def main_wait_successful(i):
print("[main] Parent is alive, spawning (and explicitly waiting for) child")
t = structio.clock()
async with structio.create_pool() as pool:
@ -27,17 +27,17 @@ async def main_wait_successful():
# in this example we could've just awaited the coroutine directly,
# so it's a bad show for the feature, but you could theoretically
# pass the object around somewhere else and do the awaiting there
print(f"[main] Child has returned: {await pool.spawn(successful, 'test', 5)}")
print(f"[main] Child has returned: {await pool.spawn(successful, 'test', i)}")
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
async def main_wait_failing():
async def main_wait_failing(i):
print("[main] Parent is alive, spawning (and explicitly waiting for) child")
t = structio.clock()
try:
async with structio.create_pool() as pool:
# This never completes
await pool.spawn(failing, "test", 5)
await pool.spawn(failing, "test", i)
print("This is never executed")
except TypeError:
print(f"[main] TypeError caught!")
@ -46,6 +46,6 @@ async def main_wait_failing():
# Total time should be about 15s
structio.run(main_cancel, 5)
structio.run(main_wait_successful)
structio.run(main_wait_failing)
structio.run(main_wait_successful, 5)
structio.run(main_wait_failing, 5)