Giter VIP home page Giter VIP logo

qdb's Introduction

qdb

build status Gitter

Remote Debugger for Python

qdb powers the in-browser debugger at Quantopian

Overview

qdb is a debugger for python that allows users to debug code executing on remote machine. qdb is split into three main components that may all be running on separate hardware:

  • The client
  • The tracer
  • The server

The client is the user's interface to the debugger. All communication here is through a websocket connected to the server. This client could be any type of application. qdb provides a terminal client and emacs mode for this.

The tracer is the main debugging process. This is the actual code that the user wishes to debug. Communication here is through a socket sending json objects representing only the valid messages sent to the server from the client. A single tracer may have multiple clients connected to it.

The server is the main routing station for messages between the clients and the tracer. The server is responsible for validating that the messages from the clients are well formed and routing them to the tracer. A single server may manage multiple tracers, so it is responsible for making sure that connections are routed to the proper place. The server can clean up tracer processes whose clients have become inactive if the server manager decides. The server may also impose authentication rules to allow or disallow some connections.

Getting started

To debug a process with qdb locally, first you must start the server process.

The easiest way to do this is to execute:

$ python -m qdb.server

which will start up a server that accepts tracer connections on port 8001, and client connections on port 8002. There are a few options that may be passed to the server from the command line, to see a full list, run:

$ python -m qdb.server --help

Now that you have a server running, you may run a process under qdb. As an example, try saving the following as qdb_test.py:

from qdb import set_trace, RemoteCommandManager


def f():
    in_f = True
    return 'getting out of f'


def main():
    set_trace(
        uuid='qdb',
        host='localhost',
        port=8001,
        cmd_manager=RemoteCommandManager(),
    )
    mutable_object = {}
    print 'Hello world!'
    f()
    print mutable_object


if __name__ == '__main__':
    main()

Then, invoke the program as you normally would with:

$ python qdb_test.py

Finally, you will need to connect your client to the server so that you can actually debug the program. To connect, run the provided client found in the client directory with:

$ qdb-cli

Before you are finished, you will need to get the output from the program, in a seperate terminal, run:

$ tail -f /tmp/qdb/.qdb

This will be the realtime output from the debugger.

You are now ready to debug your process, issue the help command in the repl to see a list of available commands and functions, or begin evaluating python code in the context of the other process.

Contributions

If you would like to contribute, please see our Contribution Requests.

Requirements

To download the requirements, you can simply issue:

$ make requirements

assuming you have pip installed. You will most likely want to install into a virtualenv.

To view the development and normal requirements, see etc/requirements_dev.txt and etc/requirements.txt.

Style

To ensure that changes and patches are focused on behavior changes, the qdb codebase adheres to both PEP-8, http://www.python.org/dev/peps/pep-0008/, and pyflakes, https://launchpad.net/pyflakes/.

The maintainers check the code using the flake8 script, https://bitbucket.org/tarek/flake8/wiki/Home, which is included in the etc/requirements_dev.txt.

Before submitting patches or pull requests, please ensure that running make style and make test both pass.

Source

The source for qdb is hosted at: https://github.com/quantopian/qdb

Contact

For other questions, please contact [email protected].

qdb's People

Contributors

adamtheturtle avatar cmichelqt avatar faulkner avatar fawce avatar gitter-badger avatar jikamens avatar llllllllll avatar rgbkrk avatar richafrank avatar thisguycodes avatar toddrme2178 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  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

qdb's Issues

Cannot convert to json error in tracer

While getting local variable list in qdb-client error is thrown in the tracer program as

Traceback (most recent call last):
  File "qdb_test.py", line 24, in <module>
    main()
  File "qdb_test.py", line 21, in main
    execfile("/home/local/ZOHOCORP/deepak-3386/Repos/Repos/OpenSource/httpie/httpie/__main__.py")
  File "/home/local/ZOHOCORP/deepak-3386/Repos/Repos/OpenSource/httpie/httpie/__main__.py", line 7, in <module>
    from core import main
  File "/home/local/ZOHOCORP/deepak-3386/Repos/Repos/OpenSource/httpie/httpie/__main__.py", line 7, in <module>
    from core import main
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/tracer.py", line 449, in trace_dispatch
    return self.super_.trace_dispatch(stackframe, event, arg)
  File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line
    self.user_line(frame)
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/tracer.py", line 462, in user_line
    bound_cmd_manager.next_command()
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/utils.py", line 348, in __call__
    ret = f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 248, in next_command
    return self.user_next_command(tracer)
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 498, in user_next_command
    return next(self.get_commands(tracer))()
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 485, in <lambda>
    yield lambda: command(tracer, event.get('p'))
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 679, in command_locals
    self.send_event('locals', tracer.curframe_locals)
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 237, in send_event
    self.send(fmt_msg(event, payload, serial=json.dumps))
  File "/usr/local/lib/python2.7/dist-packages/qdb-0.1.0-py2.7.egg/qdb/comm.py", line 72, in fmt_msg
    js=serial(frame)
  File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <module 'sys' (built-in)> is not JSON serializable

Note:
the value of frame in comm.py is {'p': {'sys': <module 'sys' (built-in)>, 'os': <module 'os' from '/usr/lib/python2.7/os.pyc'>}, 'e': 'locals'}

qdb swallows (some) program output

I noticed when running the example that the print statements don't actually come out on stdout anymore, but instead go to the tmp file. With some testing I determined this is all print statements, but not writes directly to sys.stdout.

I don't necessarily disagree with having program output written to the tmp file (having the program output and the debugger output in the same place is convenient, and even mimics was the standard pdb does), nor am I advocating for use of print statements in code, but I definitely don't think that it should be modifying program behaviour like this, and this may cause qdb to be unusable in some situations. I haven't investigated how this gagging is done so I also don't know if it could affect things.

TLDR;
Code run with set_trace() should produce the same output as code run normally.

Standardize docstrings

Currently, the docstrings do not follow any standard making it hard to understand functions quickly. They should be standardized.

Terminal Command Manager

There should exist a command manager that works in your terminal, providing an experience similar to pdb

Python 3 tracer

While the server requires gevent (and thus python 2), the tracer could be written to use python 3.

breakpoints in a function which to be called by a thread or threads is not noticed.

check the following example

`#!/usr/bin/python

import thread
import time

def print_time( threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s" % ( threadName, time.ctime(time.time()) )

try:
thread.start_new_thread( print_time, ("Thread-1", 2, ) )
thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
print "Error: unable to start thread"

while 1:
pass`

i inserted a breakpoint at line no 12. but it did not stop.

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.