Skip to content
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

pdb error when stepping through generator #77509

Closed
Ricyteach mannequin opened this issue Apr 22, 2018 · 6 comments
Closed

pdb error when stepping through generator #77509

Ricyteach mannequin opened this issue Apr 22, 2018 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Ricyteach
Copy link
Mannequin

Ricyteach mannequin commented Apr 22, 2018

BPO 33328
Nosy @pitrou, @xdegaye, @serhiy-storchaka, @1st1, @Ricyteach
Files
  • demo.py: demo of error
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-04-29.18:01:22.087>
    created_at = <Date 2018-04-22.03:03:52.986>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'pdb error when stepping through generator'
    updated_at = <Date 2018-04-29.18:01:22.085>
    user = 'https://github.com/Ricyteach'

    bugs.python.org fields:

    activity = <Date 2018-04-29.18:01:22.085>
    actor = 'Ricyteach'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-04-29.18:01:22.087>
    closer = 'Ricyteach'
    components = ['Library (Lib)']
    creation = <Date 2018-04-22.03:03:52.986>
    creator = 'Ricyteach'
    dependencies = []
    files = ['47545']
    hgrepos = []
    issue_num = 33328
    keywords = []
    message_count = 6.0
    messages = ['315586', '315587', '315588', '315589', '315893', '315903']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'xdegaye', 'serhiy.storchaka', 'yselivanov', 'Ricyteach']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33328'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @Ricyteach
    Copy link
    Mannequin Author

    Ricyteach mannequin commented Apr 22, 2018

    Hello:

    The attached python file runs a pdb interactive session for a generator. It produces an error in Python 3.7 Beta 3, but no error in 3.6.

    I searched for this issue and there do seem to be things that are related to it already, but I haven't investigated the cause of this issue and am not acquainted with the details of the pdb module, so I was unable to determine whether previous reports discuss this same problem.

    @Ricyteach Ricyteach mannequin added the 3.7 (EOL) end of life label Apr 22, 2018
    @Ricyteach
    Copy link
    Mannequin Author

    Ricyteach mannequin commented Apr 22, 2018

    The interactive session result is below:

    GeneratorExit

    Exception ignored in: <async_generator object _ag at 0x0000019E069AAD90>
    Traceback (most recent call last):
      File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\types.py", line 27, in _ag
      File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\bdb.py", line 90, in trace_dispatch
      File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\bdb.py", line 128, in dispatch_call
      File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\bdb.py", line 250, in break_anywhere
      File "C:\Users\ricky\AppData\Local\Programs\Python\Python37\lib\bdb.py", line 49, in canonic
    AttributeError: 'NoneType' object has no attribute 'abspath'

    @Ricyteach Ricyteach mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 22, 2018
    @serhiy-storchaka
    Copy link
    Member

    Thank you for your report Rick. But I get the same error in 3.6.

    An AttributeError is raised if the debugger runs at the interpreter shutdown stage (sys.is_finalizing() returns True). sys.path was set to None at the beginning of modules cleanup. The debugger traces the _ag() asynchronous generator in types.py. You can see some details when run Python with option -v.

    $ ./python -v ../demo.py
    ...
    import 'pdb' # <_frozen_importlib_external.SourceFileLoader object at 0x7f5b45debae8>
    # extension module 'readline' loaded from '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug/readline.cpython-38dm-x86_64-linux-gnu.so'
    # extension module 'readline' executed from '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug/readline.cpython-38dm-x86_64-linux-gnu.so'
    import 'readline' # <_frozen_importlib_external.ExtensionFileLoader object at 0x7f5b45d94608>
    GeneratorExit
    # clear builtins._
    # clear sys.path
    # clear sys.argv
    ...
    # cleanup[3] wiping re
    # destroy _locale
    # destroy sre_compile
    # destroy copyreg
    # cleanup[3] wiping enum
    # cleanup[3] wiping types
    Exception ignored in: <async_generator object _ag at 0x7f6de03f0eb8>
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/types.py", line 27, in _ag
      File "/home/serhiy/py/cpython/Lib/bdb.py", line 90, in trace_dispatch
      File "/home/serhiy/py/cpython/Lib/bdb.py", line 128, in dispatch_call
      File "/home/serhiy/py/cpython/Lib/bdb.py", line 250, in break_anywhere
      File "/home/serhiy/py/cpython/Lib/bdb.py", line 49, in canonic
    AttributeError: 'NoneType' object has no attribute 'abspath'

    Adding "del _ag" in types.py fixes this issue. But there are open questions.

    Is it good that the debugger is enabled at the shutdown stage?

    Why the code of the never used asynchronous generator is executed at all?

    @serhiy-storchaka serhiy-storchaka added the 3.8 only security fixes label Apr 22, 2018
    @Ricyteach
    Copy link
    Mannequin Author

    Ricyteach mannequin commented Apr 22, 2018

    I am on Anaconda 4.5.1 on Windows 10 (Python 3.6.5). I have confirmed that I DO get the error on another machine with the same version installed, so the lack of an error seems specific to my current machine. I do not know what could be causing this; it is very odd.

    @xdegaye
    Copy link
    Mannequin

    xdegaye mannequin commented Apr 29, 2018

    This is a duplicate of bpo-13044.

    Why the code of the never used asynchronous generator is executed at all?

    The destructor of the asynchronous generator is called during python finalization while the trace is still active. Here is the backtrace where python is stopped just upon entering the debugger and before the exception is raised by bdb:

    #0 call_trace_protected (func=0x5555556c0a5b <trace_trampoline>,
    obj=<method at remote 0x7ffff6f46c98>, tstate=tstate@entry=0x555555af5eb0,
    frame=frame@entry=Frame 0x7ffff6e63218, for file /home/xavier/src/python/master/Lib/types.py, line 27, in _ag (), what=what@entry=0, arg=None) at Python/ceval.c:4228
    #1 0x00005555556757f9 in _PyEval_EvalFrameDefault (
    f=Frame 0x7ffff6e63218, for file /home/xavier/src/python/master/Lib/types.py, line 27, in _ag (), throwflag=1) at Python/ceval.c:843
    #2 0x000055555567445d in PyEval_EvalFrameEx (
    f=f@entry=Frame 0x7ffff6e63218, for file /home/xavier/src/python/master/Lib/types.py, line 27, in _ag (), throwflag=throwflag@entry=1) at Python/ceval.c:536
    #3 0x000055555575c0d2 in gen_send_ex (gen=gen@entry=0x7ffff6e27d48, arg=<optimized out>,
    exc=exc@entry=1, closing=closing@entry=1) at Objects/genobject.c:221
    #4 0x000055555575c66b in gen_close (gen=gen@entry=0x7ffff6e27d48, args=args@entry=0x0)
    at Objects/genobject.c:371
    #5 0x000055555575c7f1 in _PyGen_Finalize (self=<async_generator at remote 0x7ffff6e27d48>)
    at Objects/genobject.c:84
    #6 0x00005555555f7c7d in PyObject_CallFinalizer (
    self=self@entry=<async_generator at remote 0x7ffff6e27d48>) at Objects/object.c:286
    #7 0x00005555555f89c0 in PyObject_CallFinalizerFromDealloc (
    self=self@entry=<async_generator at remote 0x7ffff6e27d48>) at Objects/object.c:303
    #8 0x000055555575ba27 in gen_dealloc (gen=gen@entry=0x7ffff6e27d48) at Objects/genobject.c:127
    #9 0x00005555555f8a7e in _Py_Dealloc (op=<async_generator at remote 0x7ffff6e27d48>)
    at Objects/object.c:1933
    #10 0x00005555555ea25b in insertdict (mp=mp@entry=0x7ffff6e53d00, key=key@entry='_ag',
    hash=-1842969574970988536, value=value@entry=None) at Objects/dictobject.c:1067
    #11 0x00005555555eb8a0 in PyDict_SetItem (
    op=op@entry=Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a struct/class/union.:
    , key='_ag', value=None) at Objects/dictobject.c:1454
    #12 0x00005555555f764f in _PyModule_ClearDict (
    d=Python Exception <class 'gdb.error'> Attempt to extract a component of a value that is not a struct/class/union.:
    ) at Objects/moduleobject.c:606
    #13 0x00005555555f793f in _PyModule_Clear (m=m@entry=<module at remote 0x7ffff6e57758>)
    at Objects/moduleobject.c:577
    #14 0x000055555569debe in PyImport_Cleanup () at Python/import.c:544
    #15 0x00005555556ac463 in Py_FinalizeEx () at Python/pylifecycle.c:1094
    #16 0x00005555555b2136 in pymain_main (pymain=pymain@entry=0x7fffffffe420) at Modules/main.c:2664
    #17 0x00005555555b22c3 in _Py_UnixMain (argc=<optimized out>, argv=<optimized out>)
    at Modules/main.c:2697
    #18 0x00005555555ad403 in main (argc=<optimized out>, argv=<optimized out>)
    at ./Programs/python.c:15

    @Ricyteach
    Copy link
    Mannequin Author

    Ricyteach mannequin commented Apr 29, 2018

    Closed as duplicate of bpo-13044.

    @Ricyteach Ricyteach mannequin closed this as completed Apr 29, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant