How do I use pdb on the host rather than the webclient?
- Vorherrschende Sprache
- Python
- Sterne
- 734
- Forks
- 412
- Ø Merge
- 1 T. 5 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
I've asked this question on stackoverflow, but I don't think I'm going to get an answer there.
I want to log to the terminal Jupyter is running in rather than the notebook. I find running IPDB in a webpage really tedious. I'm developing for Jupyter, not on it.
IPython/Jupyter patches stderr, stdin and stdout with a special file. But I can get the originals with `sys.__stdin__`.
I've tried creating a custom pdb class, but a few broken things happen.
import sys
import pdb
mypdb = pdb.Pdb(
stdin=sys.__stdin__,
stdout=sys.__stdout__,
readrc=False
)
mypdb.set_trace()
It immediately terminates execution, but it does print to the correct console.
[![Console][1]][1]
[![Jupyter][2]][2]
[1]: https://i.stack.imgur.com/CSBbi.png
[2]: https://i.stack.imgur.com/iyH0Y.png
If I run the following in Jupyter, the behavior changes to be even more strange.
import sys
import pdb
sys.stdin = sys.__stdin__
sys.stderr = sys.__stderr__
sys.stdout = sys.__stdout__
pdb.set_trace()
Instead of crashing immediately it now debugs in Jupyter _but also_ prints the `ipdb` output in the console non-interactively.
Beitragsleitfaden
Rechercherichtung
Start by reproducing the custom pdb and sys.__stdin__/__stdout__ examples in a Jupyter kernel, comparing terminal and notebook behavior. Trace how IPython/Jupyter patches standard streams and define done as interactive pdb working in the host terminal without terminating execution or duplicating output in the notebook.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- jupyter, python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100