This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pdb docs need to contain a statement on threads/multithreaded debugging
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Attila-Mihaly Balazs, bar.harel, blueyed, krichter, pablogsal, xdegaye
Priority: normal Keywords:

Created on 2015-01-04 10:21 by krichter, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
pdb_thread.py xdegaye, 2015-01-10 11:10
Messages (7)
msg233409 - (view) Author: Karl Richter (krichter) Date: 2015-01-04 10:21
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.
msg233816 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2015-01-10 11:10
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)
msg233819 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2015-01-10 11:19
The pdb documentation could make an explicit reference to the documentation of sys.settrace() where it is explained that the function is thread specific.
msg233860 - (view) Author: Karl Richter (krichter) Date: 2015-01-11 18:01
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)
msg233861 - (view) Author: Karl Richter (krichter) Date: 2015-01-11 18:04
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.
msg286377 - (view) Author: Attila-Mihaly Balazs (Attila-Mihaly Balazs) Date: 2017-01-27 16:54
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).
msg376467 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-09-06 19:03
See also https://bugs.python.org/issue41571
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67352
2020-09-19 19:01:34georg.brandlsetnosy: - georg.brandl
2020-09-06 19:03:41pablogsalsetnosy: + pablogsal
messages: + msg376467
2020-09-06 17:29:22bar.harelsetnosy: + bar.harel
2019-04-27 04:46:35blueyedsetnosy: + blueyed
2017-01-27 16:54:56Attila-Mihaly Balazssetnosy: + Attila-Mihaly Balazs
messages: + msg286377
2015-01-11 18:04:47krichtersetmessages: + msg233861
2015-01-11 18:01:33krichtersetmessages: + msg233860
2015-01-10 11:19:53xdegayesetmessages: + msg233819
2015-01-10 11:10:50xdegayesetfiles: + pdb_thread.py
nosy: + xdegaye
messages: + msg233816

2015-01-04 21:33:02ned.deilysetnosy: + georg.brandl
2015-01-04 10:21:23krichtercreate