-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Reduce extraneous exception frames #640
Conversation
status of our reference exception: Traceback (most recent call last):
File "demo.py", line 58, in <module>
test_multiplexer_with_error()
File "demo.py", line 55, in test_multiplexer_with_error
trio.run(runner2)
File "/.../site-packages/trio/_core/_run.py", line 1314, in run
return result.unwrap()
File "/.../site-packages/outcome/_sync.py", line 107, in unwrap
raise self.error
File "/.../site-packages/trio/_core/_run.py", line 1004, in init
self.entry_queue.spawn()
File "/.../site-packages/trio/_core/_run.py", line 362, in __aexit__
type(new_exc), new_exc, new_exc.__traceback__
File "/.../site-packages/trio/_core/_ki.py", line 162, in wrapper
return fn(*args, **kwargs)
File "/.../site-packages/trio/_core/_run.py", line 230, in __exit__
raise filtered_exc
File "demo.py", line 52, in runner2
nursery.start_soon(writer2, mx, (7,9))
File "/.../site-packages/trio/_core/_run.py", line 362, in __aexit__
type(new_exc), new_exc, new_exc.__traceback__
File "/.../site-packages/trio/_core/_ki.py", line 162, in wrapper
return fn(*args, **kwargs)
File "/.../site-packages/trio/_core/_run.py", line 230, in __exit__
raise filtered_exc
File "demo.py", line 15, in reader
raise e
File "demo.py", line 9, in reader
value = await mx[key]
File "multiplexer.py", line 41, in __getitem__
value = await trio.hazmat.wait_task_rescheduled(abort_fn)
File "/.../site-packages/trio/_core/_traps.py", line 165, in wait_task_rescheduled
return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
File "/.../site-packages/outcome/_sync.py", line 107, in unwrap
raise self.error
Exception: Ka-Boom! |
Reference exception after the reworked cancel scope-to-nursery exit exception path (unfortunately at the cost of another failure in test_run.py): Traceback (most recent call last):
File "demo.py", line 58, in <module>
test_multiplexer_with_error()
File "demo.py", line 55, in test_multiplexer_with_error
trio.run(runner2)
File "/.../site-packages/trio/_core/_run.py", line 1316, in run
return result.unwrap()
File "/.../site-packages/outcome/_sync.py", line 107, in unwrap
raise self.error
File "/.../site-packages/trio/_core/_run.py", line 1006, in init
self.entry_queue.spawn()
File "/.../site-packages/trio/_core/_run.py", line 372, in __aexit__
raise scope_exc
File "demo.py", line 52, in runner2
nursery.start_soon(writer2, mx, (7,9))
File "/.../site-packages/trio/_core/_run.py", line 372, in __aexit__
raise scope_exc
File "demo.py", line 15, in reader
raise e
File "demo.py", line 9, in reader
value = await mx[key]
File "multiplexer.py", line 41, in __getitem__
value = await trio.hazmat.wait_task_rescheduled(abort_fn)
File "/.../site-packages/trio/_core/_traps.py", line 165, in wait_task_rescheduled
return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
File "/.../site-packages/outcome/_sync.py", line 107, in unwrap
raise self.error
Exception: Ka-Boom! |
1cb40da
to
a309a76
Compare
This changes the public API in a few ways:
I think we do want to eventually make the changes proposed in #607, and this gets us closer, so that's good. But the API changes are going to take more finagling (e.g. deprecating some stuff, and the proposal there has So specifically:
|
Thank you. I made CancelScope itself the context manager only for implementation convenience. Instead I could make a separate CancelScopeManager (if indeed that saves frames vs. |
Well, we are planning to make |
than @contextmanager to avoid extraneous exception frames.
a309a76
to
a12998c
Compare
It's trivial to move the enter/exit between CancelScopeManager and CancelScope (and we now have a commit to refer to for exactly that when the time comes), so I went with CancelScopeManager over I've renamed to |
Strange – this says:
In all cases, the crash appears to be when a task finishes, and we walk through its cancel stack unregistering the task from all the cancel scopes... and one of the cancel scopes is like "what? this task wasn't registered in the first place". So like... somehow the task's list of scopes its inside, the the scope's list of tasks inside it, are getting out of sync. |
To further reduce extraneous exception frames, CancelScope gets create() constructor and close() methods, which nursery __aexit__ uses directly rather than going through a scope context manager.
ready to support unbound cancel scopes.
a12998c
to
2ed38fb
Compare
Codecov Report
@@ Coverage Diff @@
## master #640 +/- ##
==========================================
+ Coverage 99.31% 99.31% +<.01%
==========================================
Files 93 93
Lines 10968 10985 +17
Branches 783 786 +3
==========================================
+ Hits 10893 10910 +17
Misses 56 56
Partials 19 19
Continue to review full report at Codecov.
|
This is so, so awesome. Can you add a newsfragment, I guess |
For #56:
__aexit__
manuallyTODO:
test_nursery_exception_chaining_doesnt_make_context_loops()
test error__aexit__
manuallytest_slow_abort_edge_cases()
etc. test errors