Giter Club home page Giter Club logo

python-web-pdb's Introduction

Web-PDB

GitHub Action tests PyPI version

Web-PDB is a web-interface for Python's built-in PDB debugger. It allows to debug Python scripts remotely in a web-browser.

Important Notice

Currently this project is in a minimum maintenance mode. It means that I will try to maintain compatibility with new Python versions and address critical issues, if any arise. But at the moment I have no time or resources to develop new features or properly review external contributions. That is why only pull requests with bug fixes will be prioritized. Other issues or pull requests may or may not be reviewed or accepted.

Features

  • Responsive design based on Bootstrap.
  • Python syntax highlighting with Prism ("Okaida" theme).
  • Supports all PDB features.
  • Standard input and output can be redirected to the web-console to interact with Python scripts remotely.
  • Current file box tracks current position in a file being executed. Red line numbers indicate breakpoints, if any.
  • Globals and Locals boxes show local and global variables in the current scope. Special variables that start and end with double underscores __ are excluded (you can always view them using PDB commands).
  • Command history that stores up to 10 last unique PDB commands (accessed by arrow UP/DOWN keys).
Web-PDB screenshot

Web-PDB console in Chrome browser

Usage

Install Web-PDB into your working Python environment:

pip install web-pdb

Insert the following line into your Python program at the point where you want to start debugging:

import web_pdb; web_pdb.set_trace()

The set_trace() call will suspend your program and open a web-UI at the default port 5555 (port value can be changed). Enter in your browser's address bar: http://<your Python machine hostname or IP>:5555, for example http://monty-python:5555, and you should see the web-UI like the one on the preceding screenshot. Now you can use all PDB commands and features. Additional Current file, Globals and Locals information boxes help you better track your program runtime state.

Note: it is strongly recommended to work with the Web-PDB web-UI only in one browser session. With more than one browser window accessing the web-UI it may display incorrect data in one or more browser sessions.

Subsequent set_trace() calls can be used as hardcoded breakpoints.

Web-PDB is compatible with the new breakpoint() function added in Python 3.7. Set environment variable PYTHONBREAKPOINT="web_pdb.set_trace" to launch Web-PDB with breakpoint().

Additionally, Web-PDB provides catch_post_mortem context manager that can catch unhandled exceptions raised within its scope and automatically start PDB post-mortem debugging session. For example:

import web_pdb

with web_pdb.catch_post_mortem():
    # Some error-prone code
    assert foo == bar, 'Oops!'

For more detailed info about the Web-PDB API read docstrings in the ./web_pdb/__init__.py file.

The inspect Command

Web-PDB provides inspect or i command that is not present in the original PDB. This command outputs the list of object's members along with their values. Syntax: inspect <object_name> or i <object_name>.

Special members with names enclosed in double underscores (__) are ignored.

Considerations for Multithreading and Multiprocessing Programs

Multithreading

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.

Multiprocessing

Each process can have its own debugger instance provided you call set_trace with a different port value for each process. This way you can debug each process in a separate browser tab/window. To simplify this you can use set_trace(port=-1) to select a random port between 32768 and 65536.

Compatibility

  • Python: 3.6+
  • Browsers: Firefox, Chrome (all modern browsers should work)

License

MIT, see LICENSE.txt.

The debugger icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY.

python-web-pdb's People

Contributors

brightcells avatar dependabot[bot] avatar lijenicol avatar maiamcc avatar romanvm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-web-pdb's Issues

can web pdb name be wpdb?

Problem: Fast implementation without special characters.
Wanted: instead of import web_pdb we should import like this import wpdb

Awesome

Hi @romanvm,
Thanks for this great tool, i'm used web-pdb inside docker container for my team.
It's very usefull, congratulations!!

can't access sys.stdin.read function

$ pip install -U web-pdb
$ cat a.py
import web_pdb; web_pdb.set_trace(port=5678)
$ python a.py

# Open browser in http://127.0.0.1:5678
(Pdb) import sys; sys.stdin.read
<bound method WebConsole.readline of <web_pdb.web_console.WebConsole object at 0x00000123C7ACA490>>
(Pdb) sys.stdin.read(1)
*** TypeError: readline() takes 1 positional argument but 2 were given

Support for other debuggers

Thanks for this awesome tool!

If I may suggest a feature - it would be cool to be able to use, say pydbgr under this.

Server stops/quit

I am trying to runa simple set_trace, but it keeps quiting automatically after starting.
Any ideas what I can try?

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import web_pdb; web_pdb.set_trace()
Web-PDB: starting web-server on STUDIO-SSD:5555...
Web-PDB: stopping web-server...
Web-PDB: web-server stopped.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gtalarico\AppData\Local\Programs\Python\Python27\Lib\bdb.py", line 53, in trace_dispatch
    return self.dispatch_return(frame, arg)
  File "web_pdb\__init__.py", line 112, in dispatch_return
    return Pdb.dispatch_return(self, frame, arg)
  File "C:\Users\gtalarico\AppData\Local\Programs\Python\Python27\Lib\bdb.py", line 91, in dispatch_return
    if self.quitting: raise BdbQuit
bdb.BdbQuit

command-line interface

I'd love to be able to just web-pdb "$(which my_script)" --some-cmdline-option in a terminal without writing a Python script first. Otherwise, this is great, thank you!

Unable to see source code

I'm using web-db in the context of remote debug (on the same machine) with a tool call FME. This tool is a GUI ETL (Extract Transform ans load) that manupulates spatial information. In FME we can include python scripts to create specific manipulations that are not supplied by the basic GUI tools. When I include a python script that is stored on the file disk system and referenced with
from aaa import bbb there is no problem and I can debug and see my code/variable in the browser. There is another mode in FME tool, where we can write directly the python code which is not stored on the file disk system and we do not need to import it (the python code is probably loaded dynamically). When I use the latter method, I can start web-pdb in the browser but I cannot see the python source code and neither the variables but I know web-pdb is working as I can print the content of the variable from the PDB window (at the bottom) and step blindly from line to line. Is there something I'm doing wrongly, if not it would be very useful to adapt web-pdb for that context.

Becomes briefly unresponsive while submittiting command.

I'm connecting to a raspberry pi over wifi, so things aren't the quickest.

It would be great if whatever is submitting the commands / redrawing was decoupled from the input box.

At the moment when I submit a command everything stops for a bit, it would seem much more responsive if I could type during this second or so.

web-pdb just hangs on FireTV

I don't know if this is expected, but I have searched all the docs and can't find any mention of it and I can't find anywhere else to ask. web-pdb works perfectly for me on a Windows 10 laptop, but any calls to web_pdb.set_trace() when my app is running on FireTV (Android fork) just results in a hang with no web-pdb popup and no access via the 5555 port.

Is web-pdb supposed to be compatible with Android/FireTV?

information deprecated collections in 3.10

Hello,
I have a warning to python 3.9 with odoo

web_1  |     import web_pdb;web_pdb.set_trace()
web_1  |   File "/usr/local/lib/python3.9/dist-packages/web_pdb/__init__.py", line 40, in <module>
web_1  |     from .web_console import WebConsole
web_1  |   File "/usr/local/lib/python3.9/dist-packages/web_pdb/web_console.py", line 39, in <module>
web_1  |     from .wsgi_app import app
web_1  |   File "/usr/local/lib/python3.9/dist-packages/web_pdb/wsgi_app.py", line 33, in <module>
web_1  |     import bottle
web_1  |   File "/usr/local/lib/python3.9/dist-packages/bottle.py", line 87, in <module>
web_1  |     from collections import MutableMapping as DictMixin

WARNING test py.warnings: /usr/local/lib/python3.9/dist-packages/bottle.py:87: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated sin
ce Python 3.3, and in 3.10 it will stop working

Can it support ironpython?

I want to use this tool under ironpython(https://github.com/IronLanguages/ironpython2). but it seems cannot support. Will It can support in the future?

2018-07-12 17:53:35,422: root - web_console:109 - CRITICAL - Web-PDB: starting web-server on weston-x270:5555...
Traceback (most recent call last):
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 86, in run
self.finish_response()
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 128, in finish_response
self.write(data)
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 212, in write
self.send_headers()
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 270, in send_headers
self.send_preamble()
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 191, in send_preamble
self._write('HTTP/%s %s\r\n' % (self.http_version,self.status))
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 391, in write
self.stdout.write(data)
File "D:\IronPython.2.7.8\Lib\socket.py", line 328, in write
self.flush()
File "D:\IronPython.2.7.8\Lib\socket.py", line 304, in flush
view = memoryview(data)
TypeError: expected IBufferProtocol, got str
2018-07-12 17:53:55,145: asyncore_wsgi - init:167 - ERROR - Exception in <asyncore_wsgi.AsyncWsgiHandler connected 127.0.0.1:22526 at 0x9f>!
Traceback (most recent call last):
File "D:\IronPython.2.7.8\Lib\site-packages\asyncore_wsgi_init
.py", line 152, in handle_write
handler.run(self.server.get_app())
File "D:\IronPython.2.7.8\Lib\wsgiref\handlers.py", line 92, in run
self.close()
File "D:\IronPython.2.7.8\Lib\wsgiref\simple_server.py", line 32, in close
self.request_handler.log_request(
AttributeError: 'NoneType' object has no attribute 'split'

web_pdb hangs at page load

Apparently because of server hangs at some variable formatting:

I waited a few dozen seconds and then hit Ctrl+C and got somehow this stack trace:

  File "/usr/lib/python3.10/bdb.py", line 90, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.10/bdb.py", line 114, in dispatch_line
    self.user_line(frame)
  File "/usr/lib/python3.10/pdb.py", line 253, in user_line
    self.interaction(frame, None)
  File "/usr/lib/python3.10/pdb.py", line 348, in interaction
    self._cmdloop()
  File "/usr/lib/python3.10/pdb.py", line 317, in _cmdloop
    self.message('--KeyboardInterrupt--')
  File "/usr/lib/python3.10/pdb.py", line 448, in message
    print(msg, file=self.stdout)
  File "/home/vadimkantorov/.local/lib/python3.10/site-packages/web_pdb/web_console.py", line 152, in writeline
    frame_data = self._debugger.get_current_frame_data()
  File "/home/vadimkantorov/.local/lib/python3.10/site-packages/web_pdb/__init__.py", line 174, in get_current_frame_data
    'locals': self.get_locals()
  File "/home/vadimkantorov/.local/lib/python3.10/site-packages/web_pdb/__init__.py", line 214, in get_locals
    return self._format_variables(self.curframe_locals)
  File "/home/vadimkantorov/.local/lib/python3.10/site-packages/web_pdb/__init__.py", line 189, in _format_variables
    return '\n'.join(sorted(f_vars))
KeyboardInterrupt

Maybe some variables are super-huge strings, and it tries to format them and thus hanging?

C# + PythonNet use case

Hi, awesome repo! :)

I was testing web-pdb using C# + https://github.com/pythonnet/pythonnet , specifically calling Python from a C# process. Example: PythonEngine.RunSimpleString("import web_pdb; web_pdb.set_trace()");

My issue/feature request/advice request, is that web-pdb is closing when coming back from the Python code to the C# side, getting the *** Thread finished *** message from https://github.com/romanvm/python-web-pdb/blob/master/web_pdb/__init__.py#L166 __init__.py:dispatch_return()
and I'd like it to continue to live until the process ends or maybe the WebPdb instance is disposed/shutdown.

Thoughts?
Thanks!

Is it possible to plot in debug?

Hello and, first, thanks for web-pdb!

I was wondering if it is possible to have some integration/support for showing matplotlib plots directly in the browser. That would help a lot when debugging scientific applications, in which plots are extremely useful.
I know this could be a long shot, but I really think there is an empty spot for this kind of debugging.

Is it possible?

Trying to use it with Odoo but no results.

Very exciting library! I'm trying to use it with Odoo but port 5555 outputs connection refused.
Maybe I'm missing something? Or if you have any advice, would be appreciated.

local variables can not be modified

While stepping through a function, I tried to change the value of a local variable.
Although web-pdb echoes the command as usual, the value always stays the same.

Globals can be changed as expected.

web python debugger stuck

Hi firstly thanks for this useful tool. However I face a problem when I try to just continue the execution. When I look at my app , it is correct that the app is continued . But after that , when I want to quit the session, it just stuck or hang , and I reload the web debugger, it shows the same which is the last command I used which is continue . I could not do anything about it except to rerun container. How do I solve this ? thanks in advance

Resize-able / exchangeable frames

Would it be possible to implement handles to resize frames (e.g. decrease height of "PDB Console") ?
Or to switch places of two frames.

I usually focus more on the code than on PDB output :)

Word-wrap output in lower pane

It would be very nice if the output could be wrapped in the lower pane. This would be especially handy when calling dir() down there

Remove '...' after address to cmd+click directly from VSCode

Not a big deal but trying to CMD+Click, from Visual Studio Code terminal, on the hostname:port when pdb start doesn't directly open the browser but open the VSC popup window saying 'No matching results', as the three dots are recognised as part of the input.

Adding a space in between or deleting them should solve the issue, and it could improve the workflow.

immagine

Apart from that, your web-pdb has already saved me a looot of time! Thank you!

AttributeError when calling set_trace() on Python 3.5

$ python test.py     
Web-PDB: starting web-server on laptop:5555...
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import web_pdb; web_pdb.set_trace()
  File "/home/user/.local/share/virtualenvs/test/lib/python3.5/site-packages/web_pdb/__init__.py", line 209, in set_trace
    pdb = WebPdb(host, port, patch_stdstreams)
  File "/home/user/.local/share/virtualenvs/test/lib/python3.5/site-packages/web_pdb/__init__.py", line 70, in __init__
    Pdb.__init__(self, stdin=self.console, stdout=self.console)
  File "/home/user/.local/share/virtualenvs/test/lib/python3.5/site-packages/pdb.py", line 215, in __init__
    self.stdout = self.ensure_file_can_write_unicode(self.stdout)
  File "/home/user/.local/share/virtualenvs/test/lib/python3.5/site-packages/pdb.py", line 219, in ensure_file_can_write_unicode
    if not hasattr(f, 'stream') and f.encoding and f.encoding.lower() != 'utf-8':
AttributeError: 'WebConsole' object has no attribute 'encoding'

This is Python 3.5.1 64 bit on Ubuntu 16.04 in a virtualenv in a file with a simple for loop, started in a ZSH shell.
This is with P

set_trace() only works the first time

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()
    ...

Cohexistance with pdbpp

When pdbpp and web_pdb are installed in the same env, web_pdb is unable to run giving following traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/Code/module.py", line 1772, in backup_data_tgz
    web_pdb.set_trace()
  File "/home/user/.virtualenvs/venv/lib/python3.10/site-packages/web_pdb/__init__.py", line 256, in set_trace
    pdb = WebPdb(host, port, patch_stdstreams)
  File "/home/user/.virtualenvs/venv/lib/python3.10/site-packages/pdbpp.py", line 276, in __call__
    obj.__init__(*args, **kwargs)
TypeError: WebPdb.__init__() got an unexpected keyword argument 'start_filename'

This happens because, by default, pdbpp hijacks pdb.

Setting environment variable PDBPP_HIJACK_PDB=0 solves this issue.

As I stumbled upon this error and struggled a bit to find the remediation I'm asking if it would be possible to mention the workaround in the README.md or to deal with this in web_pdb checking if pdbpp is installed and setting the environment so to make it work.

If you are not willing to do anything I'd understand as it seems more an issue of pdbpp but then I'd just leave this issue as closed for others to find it :)

Autocompletion / ipdb base?

I almost always use ipdb (as opposed to pdb) because of the autocomplete. Mainly all the same reasons I use the IPython REPL instead of the Python REPL.

Would it be possible to add support for ipython to web-pdb?

Love this project. Was delighted to have discovered it just now. Great work and very useful idea for debugging a remote machine.

Spam Ajax GET requests to http://127.0.0.1:5555/output/update

Hello! When I open the debugger in my browser and check the console I see that it's making repeated GET requests to http://127.0.0.1:5555/output/update in the background. These fail with 403 (Forbidden) since there's nothing in my application at that URL.

Is this normal? Perhaps I've missed some configuration detail?

I'm using Chrome Version 55.0.2883.95 (64-bit).

Here is a screenshot of the console:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.