Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
With the following demo code, a subgeneratoryield from from a parent generator main(), that catches exceptions and returns "good":
classInner:defsend(self,v):returnNonedef__iter__(self):returnselfdef__next__(self):returnself.send(None)defthrow(self,*exc_info):raiseStopIteration("good")defmain():return (yieldfromInner())defrun(coro):coro.send(None)try:coro.throw(Exception)exceptStopIterationase:print(e.value)run(main())
when run withpython -m trace, the exception is delivered to the outer generator main() instead of being suppressed
graingert@conscientious ~/projects/cpython main ./python -m trace --count -C . demo.py Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/home/graingert/projects/cpython/Lib/trace.py", line 741, in <module> main() File "/home/graingert/projects/cpython/Lib/trace.py", line 729, in main t.runctx(code, globs, globs) File "/home/graingert/projects/cpython/Lib/trace.py", line 451, in runctx exec(cmd, globals, locals) File "demo.py", line 26, in <module> run(main()) File "demo.py", line 21, in run coro.throw(Exception) File "demo.py", line 16, in main return (yield from Inner()) ^^^^^^^^^^^^^^^^^^Exception ✘ graingert@conscientious ~/projects/cpython main ± ./python demo.py goodthe problem also occurs with the equivalent generator syntax, eg:
defInner():try:whileTrue:yieldNoneexcept:return"good"
Your environment
- CPython versions tested on:c05c31d 3.12b1
- Operating system and architecture: Ubuntu 22.04 x86_64
see also
urllib3/urllib3#3049 (comment)
nedbat/coveragepy#1635
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done