-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate test failures #2
Comments
@aleneum If you don't mind, please take a look. |
It seems like import anyio
from anyio import create_task_group, get_cancelled_exc_class, open_cancel_scope
async def cancel_soon():
await anyio.sleep(1)
raise TimeoutError("Callback was not cancelled!")
async def call_delayed(func, time):
await anyio.sleep(time)
await func()
async def main():
async with create_task_group() as tg:
async with open_cancel_scope(shield=False) as scope:
await tg.spawn(cancel_soon)
await tg.spawn(call_delayed, scope.cancel, 0.1)
anyio.run(main) |
Okay, so works: async def main():
async with open_cancel_scope(shield=False) as scope:
async with create_task_group() as tg:
await tg.spawn(cancel_soon)
await tg.spawn(call_delayed, scope.cancel, 0.1) also works: async def main():
async with create_task_group() as tg:
await tg.spawn(cancel_soon)
await tg.spawn(call_delayed, tg.cancel_scope.cancel, 0.1) |
If async def cancel_soon():
try:
await anyio.sleep(1)
raise TimeoutError("Callback was not cancelled!")
except get_cancelled_exc_class():
print("Cancel soon was cancelled")
raise the cancellation messages is shown but the |
I guess some of the weirdness is due to the fact that current scope is <anyio._backends._asyncio.CancelScope object at 0x7f67efff53c0>
cancel scope <anyio._backends._asyncio.CancelScope object at 0x7f67f012bbc0>
scope <anyio._backends._asyncio.CancelScope object at 0x7f67efff53c0> was cancelled
changes: async def process_context(self, func, model):
if self.current_context.get() is None:
try:
async with open_cancel_scope(shield=False) as scope:
self.current_context.set(scope)
return await func()
except get_cancelled_exc_class():
print(f"scope {scope} was cancelled")
return False
return await func()
async def switch_model_context(self, model):
current_scope = self.current_context.get()
running_scope = self.async_tasks.get(model, None)
if current_scope != running_scope:
self.async_tasks[model] = self.current_context.get()
if running_scope is not None:
print(f"current scope is {current_scope}")
print(f"cancel scope {running_scope}")
await running_scope.cancel() |
So how do we get the correct scope? |
it seems that |
for queing to work. tasks need to be passed to |
oh, remark. for this to work |
I applied that change to |
I added the changes that were made in transitions to deal with more complex task configurations (protected_tasks) and clean up after a trigger has been processed to prevent memory leaks when many (as in thousands) models are used. |
So, for curio the 'problem' is, that spawned tasks seem to run in the same context. |
In acbcdae I added special treatment for curio CancelScopes. I also added a test to check whether this treatment might cause callbacks to cancel themselves when they transititon to another state. It passes for now. |
Wonderful! |
just fyi: 0.8.5 has been released |
Both the
test_multiple_models
and thetest_queued
tests are failing, even with asyncio as the anyio backend.We should investigate why that happens and fix it as soon as possible.
The text was updated successfully, but these errors were encountered: