4

I'm using multi-threaded code and PDB doesn't stop on manually set breakpoints:

(pdb) b filename:lineno
(pdb) c  # Runs without stopping

What could be the reason why?

Bharel
  • 23,672
  • 5
  • 40
  • 80
  • Does this answer your question? [Is there a way to attach a debugger to a multi-threaded Python process?](https://stackoverflow.com/questions/47701/is-there-a-way-to-attach-a-debugger-to-a-multi-threaded-python-process) – Jürgen Gmach Oct 07 '20 at 20:04

2 Answers2

9

As of September 2020, Python's pdb debugger does not support multi-threading.

Attempting to break on a different thread from where pdb started, will skip the breakpoints. This is due to the current implementation using sys.settrace() which is thread-specific.

There's a ticket for implementing this functionality among other multi-threading additions.

Currently, the only option is to pdb.set_trace() on the same thread being debugged.

Bharel
  • 23,672
  • 5
  • 40
  • 80
-1

Instead of pdb use e.g. web-pdb.

https://pypi.org/project/web-pdb/

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
  • 1
    "Web-PDB maintains one debugger instance that traces only one thread. You should not call set_trace() from different threads to avoid race conditions. Each thread needs to be debugged separately one at a time." – Bharel Oct 07 '20 at 16:17
  • 2
    Thanks for the reply. I could swear I used it a couple of years ago to debug a multithreaded cli app, but apparantly it was a different one. Sorry for the wrong information! – Jürgen Gmach Oct 07 '20 at 18:01