question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set_trace() only works the first time

See original GitHub issue

The breakpoint (as in import web_pdb; web_pdb.set_trace()) works fine for the first time. But once the debugger session is ended (e.g. by typing c and pressing enter), it won’t stop again until the dev server is restarted. By “won’t stop” I mean the breakpoint no longer works.

I’m using Django==1.11.22 and web-pdb==1.5.1 in a Docker container. The breakpoint was inserted in the beginning of a view function.

def view_func(request):
    import web_pdb; web_pdb.set_trace()
    ...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
maiamcccommented, Mar 6, 2020

Hey folks, I spent this afternoon poking into this, and I think it is not a container issue, but rather a webpdb-and-threads issue. I was able to reproduce the issue locally with this toy flask app.

As far as I can tell, when webpdb exits due to a thread closing (which in most Python webserver frameworks is going to happen at the end of any web request), it leaves out a bit of cleanup; whenever the set_trace() command is hit subsequently, webpdb thinks that it’s still running (because of the neglected cleanup step from before) and so doesn’t refresh the web console connection, so the debugger doesn’t work.

Opening a PR now.

0reactions
romanvmcommented, Sep 10, 2020

Closing this because of no further feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sys.settrace only getting called at function calls, not every line
The trace function is invoked (with event set to 'call') whenever a new local scope is entered; it should return a reference to...
Read more >
The unreasonable effectiveness of sys.settrace (and ... - expLog
settrace sets a trace function that is triggered by the VM every time it enters or exits a function, processes a line of...
Read more >
sys — System-specific parameters and functions — Python ...
Get the trace function as set by settrace() . CPython implementation detail: The gettrace() function is intended only for implementing debuggers, profilers, ...
Read more >
Python Debugging With Pdb
In this first example, we'll look at using pdb in its simplest form: checking the value of a variable. Insert the following code...
Read more >
Usage and Invocations — pytest documentation
pytest -x # stop after first failure pytest --maxfail=2 # stop after two ... format pytest --tb=line # only one line per failure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found