Exemple #1
0
def set_trace(frame=None, depth=None, ip=DEFAULT_IP, port=DEFAULT_PORT):
    ''' Wrapper function to keep the same import x; x.set_trace() interface.

      We catch all the possible exceptions from pdb and cleanup.

      Parameters
      ----------
      frame : str
          The Frame
      depth : int
          The Depth
      ip : str
          The IP Address
      port : int
          The Port
  '''
    frame = vdb.find_frame(
        frame, depth if depth is not None else 2 if frame is None else 0)

    try:
        debugger = rpdb.Rpdb(addr=ip, port=port)
    except socket.error:
        if rpdb.OCCUPIED.is_claimed(port, sys.stdout):
            # rpdb is already on this port - good enough, let it go on:
            sys.stdout.write("(Recurrent rpdb invocation ignored)\n")
            return
        else:
            # Port occupied by something else.
            raise
    try:
        debugger.set_trace(frame)
    except Exception:
        import traceback
        traceback.print_exc()
Exemple #2
0
def post_mortem(tb=None, ip=DEFAULT_IP, port=DEFAULT_PORT):
    ''' Parameters
      ---------
      tb : str
          The Traceback
      ip : str
          The IP Address
      port : int
          The Port

      Raises
      ------
      ValueError
          Passes a valied traceback
  '''
    if tb is None:
        # sys.exc_info() returns (type, value, traceback) if an exception is
        # being handled, otherwise it returns None
        tb = sys.exc_info()[2]
        if tb is None:
            raise ValueError("A valid traceback must be passed if no "
                             "exception is being handled")
    r = rpdb.Rpdb(addr=ip, port=port)
    r.reset()
    r.interaction(None, tb)
Exemple #3
0
def post_mortem(tb=None, ip=DEFAULT_IP, port=DEFAULT_PORT):
    if tb is None:
        # sys.exc_info() returns (type, value, traceback) if an exception is
        # being handled, otherwise it returns None
        tb = sys.exc_info()[2]
        if tb is None:
            raise ValueError("A valid traceback must be passed if no "
                             "exception is being handled")
    r = rpdb.Rpdb(addr=ip, port=port)
    r.reset()
    r.interaction(None, tb)
Exemple #4
0
def session(sequencer):

    # If the debug flag was passed then we import pdb and
    # pause in the debugger.
    import pdb
    pdb.set_trace()

    # If the remote debug flag was passed then we setup
    # a remote debug session and pause in the debugger
    # to wait for a connection.
    import rpdb
    debugger = rpdb.Rpdb(port=12345)
    debugger.set_trace()

    with sequencer.enter_session_scope_context() as ssc:
        scope_tests(sequencer)
Exemple #5
0
def rpdb_set_trace(log=None):
    """
    convenience function to set_trace with rpdb in a control center container
    """
    import rpdb
    import subprocess

    ip = subprocess.check_output(["hostname", "-i"]).strip()
    port = 4444
    print "connect to rpdb remotely with: nc %s %d  # Control-C to exit nc" % (
        ip, port)
    if log:
        log.warn(
            "connect to rpdb remotely with: nc %s %d  # Control-C to exit nc" %
            (ip, port))
    debugger = rpdb.Rpdb(ip, port)
    debugger.set_trace()
Exemple #6
0
 def excel_color(self, color, default="#000000"):
     if color is None:
         # Dumb dirty fix to handle the library weird design
         return default
     if color.theme and color.tint:
         return "#%s" % self.theme_and_tint_to_rgb(color.theme, color.tint)
     if False and color is None or str(
             color.rgb) == "Values must be of type <class 'str'>":
         # Dumb dirty fix to handle the library weird design
         return default
     try:
         if re.search("^\w{8}$", color.rgb):
             return re.sub(r"^\w\w", "#", color.rgb)
     except TypeError:
         import rpdb
         rpdb.Rpdb().set_trace()
         log.error(
             f"could not interpret {color.rgb} ({color.rgb.__class__})")
         raise
     except AttributeError:
         return default
# remote python debugger

# install
pip install rpdb

import rpdb
debugger = rpdb.Rpdb(port=12345)
debugger.set_trace()

rpdb.Rpdb(port=12345).set_trace()

# to access the debugger
telnet host port

s(tep) - Execute the current line, stop at the first possible occasion (either in a function that is called or on the next line in the current function).
n(ext) - Continue execution until the next line in the current function is reached or it returns. (The difference between next and step is that step stops inside a called function, while next executes called functions at (nearly) full speed, only stopping at the next line in the current function.)
r(eturn) - Continue execution until the current function returns.
c(ont(inue)) - Continue execution, only stop when a breakpoint is encountered.
q(uit) - Quit from the debugger. The program being executed is aborted.
a(rgs) - Print the argument list of the current function.
l(ist) [first[, last]] - List source code for the current file.

###
dir() -- list of scope vars
dir(obj_or_var) -- list all object attributes 
Exemple #8
0
import threading
import rpdb

#debugger = rpdb.Rpdb(port=4444)
rpdb.Rpdb().set_trace()


def my_func(thread_number):
    return print('my_func called by thread N°{}'.format(thread_number))


def main():
    threads = []
    for i in range(10):
        t = threading.Thread(target=my_func, args=(i, ))
        threads.append(t)
        t.start()
        t.join()


if __name__ == "__main__":

    main()
Exemple #9
0
import sys
import time

from flask import render_template
from rq import get_current_job

from app import create_app, db
from app.email import send_email
from app.models import Task, User, Post

app = create_app()
app.app_context().push()

if app.config['TASK_DEBUG']:
    import rpdb
    debug = rpdb.Rpdb(addr="0.0.0.0", port=4445)


def _set_tast_progress(progress):
    job = get_current_job()
    if job:
        job.meta['progress'] = progress
        job.save_meta()
        task = Task.query.get(job.get_id())
        task.user.add_notification('task_progress', {
            'task_id': job.get_id(),
            'progress': progress
        })

        if progress >= 100:
            task.complete = True