Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

generator throw delivered to incorrect generator under trace #105162

Closed
Assignees
markshannon
Labels
3.12only security fixes3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-bugAn unexpected behavior, bug, or error
@graingert

Description

@graingert

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                      good

the 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

3.12only security fixes3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)release-blockertype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp