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.

pdb is not working right

See original GitHub issue

Now that code.interact() seems to be working #853, I wondered if pdb could work too. It doesn’t.

The test page:

<script type="text/javascript"
    src="https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js">
</script>
<script type="text/javascript"
    src="https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython_stdlib.js">
</script>
<body onload="brython({debug:1})">
<script type="text/python">
import pdb
pdb.set_trace()
</script>
</body>

And the output:

using indexedDB for stdlib modules cache brython.js:5198:36
Traceback (most recent call last):
  module __main__ line 2
    pdb.set_trace()
  module pdb line 1608, in set_trace
    pdb=Pdb()
  module pdb line 144, in __init__
    sys.audit("pdb.Pdb")
AttributeError: 'module' object has no attribute 'audit' brython.js:6120:9
Error: brython.js line 7674 > eval:41:354
    $factory https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js line 7674 > eval:41
    attr_error https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:6654
    $getattr https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:6765
    __init__11656 https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js line 9023 > Function:545
    __call__ https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:5553
    <anonymous> self-hosted:911
    factory https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:5731
    set_trace11758 https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js line 9023 > Function:8526
    anonymous https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js line 5240 > Function:16
    loop https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:5240
    idb_load https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:5171
    onsuccess https://cdn.jsdelivr.net/gh/brython-dev/brython@master/www/src/brython.js:5182

Neither does the new breakpoint().

using indexedDB for stdlib modules cache brython.js:5198:36
Traceback (most recent call last):
  module __main__ line 1
    breakpoint()
NameError: name 'breakpoint' is not defined

In CPython 3.7+, this is equivalent to pdb.set_trace(), but it is configurable to use other debuggers. I suppose that in Brython it would not be unreasonable for breakpoint() to use some other tool by default. Perhaps by embedding something like Brython’s web console into the page, or by using WebSockets or long polling with an external app like Clojurescript does.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreQuentelcommented, Mar 4, 2020

In the latest commit above, the interactive debugger starts to work.

When I run this code:

blabla = "azerty"

import pdb
pdb.set_trace()

I get the prompt with message (Pdb), and can enter simple commands (with this terrible Javascript popup…) like:

> blabla
'azerty'
> import re
> re
<module re>
> z = "uiop"
> blabla + z
'azertyuiop'

The issue is not yet closed - there are many other tests to do, and I didn’t implement breakpoint() - but it’s getting better…

0reactions
gilchcommented, Nov 30, 2020

When I start an interactive session from the debugger in the terminal using the interact command, I can exit that and get back to the debugger with EOF (Ctrl-D in the terminal). But that’s a bookmark in the browser. So I kind of thought the cancel button in the javascript prompt would do it instead, but alas, it doesn’t. It seems to behave like an empty input.

I even tried pasting in an EOF character using the clipboard. That’s how you have to do it in Jupyter when it runs interact in pdb, because it also runs in the browser. But this didn’t work for Brython either. I can’t type in exit() because that quits the whole program, debugger included.

Can you distinguish a [Cancel] from an [OK] or enter in the prompt and treat it as an EOF?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - pdb.set_trace() not working - Stack Overflow
Thanks guys. Anthon and wim are right. I really did not import the standard pdb.py. Instead, I import another module having the same...
Read more >
Troubleshoot Breakpoints in the Visual Studio Debugger
The PDB file is partially corrupted. Delete the file and run a clean build of the module to try to resolve the issue....
Read more >
Python Debugging With Pdb
In this hands-on tutorial, you'll learn the basics of using pdb, Python's interactive source code debugger. Pdb is a great tool for tracking...
Read more >
Problem debugging with pdb - Google Groups
two break points and they seem to save properly. I let the debugger continue through opening the test server, but when. I request...
Read more >
Frequently Asked Questions - RCSB PDB
Warning You are using a web browser that we do not support. Our website will not work properly. Please update to a newer...
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