inducer / pudb

Full-screen console debugger for Python
https://documen.tician.de/pudb/
Other
2.94k stars 226 forks source link

remote debugging with telnet fails: a Debugger instance already exists #645

Closed qrockz closed 5 months ago

qrockz commented 5 months ago

remote debugging raises error:


Traceback (most recent call last):
  File "/home/t/.local/lib/python3.11/site-packages/pudb/__init__.py", line 162, in runscript
    dbg._runscript(mainpyfile)
  File "/home/t/.local/lib/python3.11/site-packages/pudb/debugger.py", line 534, in _runscript
    self.run(statement)
  File "/usr/lib/python3.11/bdb.py", line 600, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "first.py", line 2, in <module>
    set_trace(term_size=(80, 24))
  File "/home/t/.local/lib/python3.11/site-packages/pudb/remote.py", line 278, in set_trace
    return debugger(
           ^^^^^^^^^
  File "/home/t/.local/lib/python3.11/site-packages/pudb/remote.py", line 260, in debugger
    rdb = _current[0] = RemoteDebugger(
                        ^^^^^^^^^^^^^^^
  File "/home/t/.local/lib/python3.11/site-packages/pudb/remote.py", line 184, in __init__
    Debugger.__init__(
  File "/home/t/.local/lib/python3.11/site-packages/pudb/debugger.py", line 192, in __init__
    raise ValueError("a Debugger instance already exists")
ValueError: a Debugger instance already exists

To Reproduce code trying to debug: first.py

from pudb.remote import set_trace
set_trace(term_size=(80, 24))
breakpoint()
num = int(input("Enter a number: "))
if (num % 2) == 0:
   print("{0} is Even".format(num))
else:
   print("{0} is Odd".format(num))
print("jlkjlkj")

pudb first.py

pudb:6899: Please start a telnet session using a command like:
telnet 127.0.0.1 6899
pudb:6899: Waiting for client...

trying to connect with other terminal to this session:

telnet 127.0.0.1 6899
Trying 127.0.0.1...
Connected to 127.0.0.1.

err

Versions

pudb v2024.1
Python 3.12.2
inducer commented 5 months ago

I think the main problem here is one of documentation. You run first.py with pudb, which creates a (non-remote) Debugger instance. Initiating remote debugging creates another (remote) debugger instance. Since the debugger instance holds handles to various Urwid guts that differ based on remote/non-remote, the non-remote instance can't be reused. So while I agree that the error message is a bit opaque for non-insiders, it is accurate.

The fix should be simple: don't run first.py with pudb, just regular python suffices.

It's an (IMO) valid question whether the message could provide better advice on what to do.

qrockz commented 5 months ago

@inducer Thank you for your reply.

don't run first.py with pudb [...]

These were the keywords which gave me the hint!

$ python3 -m pdb first.py Then jump to the first breakpoint() where pdb gives the hint to connect with telnet. \o/

Just on more question: How can I handle user input via telnet remote debugging? teln