python / cpython

The Python programming language
https://www.python.org
Other
63.12k stars 30.22k forks source link

pdb docs need to contain a statement on threads/multithreaded debugging #67352

Open fcfd9df0-fe97-4eef-90a2-7e9380d47fbd opened 9 years ago

fcfd9df0-fe97-4eef-90a2-7e9380d47fbd commented 9 years ago
BPO 23163
Nosy @blueyed, @xdegaye, @bharel, @pablogsal
Files
  • pdb_thread.py
  • 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: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'library'] title = 'pdb docs need to contain a statement on threads/multithreaded debugging' updated_at = user = 'https://bugs.python.org/krichter' ``` bugs.python.org fields: ```python activity = actor = 'georg.brandl' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'krichter' dependencies = [] files = ['37668'] hgrepos = [] issue_num = 23163 keywords = [] message_count = 7.0 messages = ['233409', '233816', '233819', '233860', '233861', '286377', '376467'] nosy_count = 6.0 nosy_names = ['blueyed', 'xdegaye', 'krichter', 'bar.harel', 'Attila-Mihaly Balazs', 'pablogsal'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue23163' versions = ['Python 3.5'] ```

    fcfd9df0-fe97-4eef-90a2-7e9380d47fbd commented 9 years ago

    Due to the fact that pdb currently simply ignores breakpoints which are set and hit in another than the main thread the docs need to contain a statement on behavior in a multithreaded environment.

    490c593f-f636-409f-bb35-6abeb38a4595 commented 9 years ago

    pdb does not ignore breakpoints which are set and hit in a non-main thread. For example with the attached script:

    $ python pdb_thread.py
    > pdb_thread.py(5)foo()
    -> lineno = 5
    (Pdb) break 6
    Breakpoint 1 at pdb_thread.py:6
    (Pdb) continue
    > pdb_thread.py(6)foo()
    -> lineno = 6
    (Pdb) threading.current_thread().name
    'fooThread'
    (Pdb)
    490c593f-f636-409f-bb35-6abeb38a4595 commented 9 years ago

    The pdb documentation could make an explicit reference to the documentation of sys.settrace() where it is explained that the function is thread specific.

    fcfd9df0-fe97-4eef-90a2-7e9380d47fbd commented 9 years ago

    My initial description was imprecise. Clearification: The fact that in

    #!/usr/bin/python
        import threading
    
        def debugging():
            def __a_thread__():
                print("2")
            a_thread = threading.Thread(target=__a_thread__)
            print("1")
    
        if __name__ == "__main__":
            debugging()

    when invoked with python -m pdb the breakpoint at line 7 is ignored, like in

        $ python -m pdb multithreaded_debugging.py 
        > /mnt/DATA/richter/examples/python/multithreaded_debugging/multithreaded_debugging.py(3)<module>()
        -> import threading
        (Pdb) break 7
        Breakpoint 1 at /mnt/DATA/richter/examples/python/multithreaded_debugging/multithreaded_debugging.py:7
        (Pdb) c
        1
        The program finished and will be restarted
        > /mnt/DATA/richter/examples/python/multithreaded_debugging/multithreaded_debugging.py(3)<module>()
        -> import threading
        (Pdb)
    fcfd9df0-fe97-4eef-90a2-7e9380d47fbd commented 9 years ago

    Sorry, I mean

    #!/usr/bin/python
        import threading
    
        def debugging():
            def __a_thread__():
                print("2")
            a_thread = threading.Thread(target=__a_thread__)
            a_thread.start()
            a_thread.join()
            print("1")
    
        if __name__ == "__main__":
            debugging()

    It's very uncommon to set the current debugging thread in the source.

    546a6683-2ac1-4017-a3ec-0692d8ee6932 commented 7 years ago

    Absolutely this. While it is good that there is at least some documentation (at sys.settrace), it is not very explicit nor is it self evident that one should look there (for example the PDB docs don't even mention settrace).

    pablogsal commented 4 years ago

    See also https://bugs.python.org/issue41571