def attach_debugger(host='localhost', port=6000, authkey='secret password'): import gluon.contrib.qdb as qdb import gluon.debug from multiprocessing.connection import Listener if isinstance(authkey, unicode): authkey = authkey.encode('utf8') if not hasattr(gluon.debug, 'qdb_listener'): # create a remote debugger server and wait for connection address = (host, port) # family is deduced to be 'AF_INET' gluon.debug.qdb_listener = Listener(address, authkey=authkey) gluon.debug.qdb_connection = gluon.debug.qdb_listener.accept() # create the backend gluon.debug.qdb_debugger = qdb.Qdb(gluon.debug.qdb_connection) gluon.debug.dbg = gluon.debug.qdb_debugger # welcome message (this should be displayed on the frontend) print 'debugger connected to', gluon.debug.qdb_listener.last_accepted return True # connection successful!
def do_quit(self): qdb.Frontend.do_quit(self) def do_exec(self, statement): interact_lock.acquire() try: # check to see if we're inside interaction if self.filename: # avoid spurious interaction notifications: self.set_burst(2) # execute the statement in the remote debugger: return qdb.Frontend.do_exec(self, statement) finally: interact_lock.release() # create the connection between threads: parent_queue, child_queue = Queue.Queue(), Queue.Queue() front_conn = qdb.QueuePipe("parent", parent_queue, child_queue) child_conn = qdb.QueuePipe("child", child_queue, parent_queue) web_debugger = WebDebugger(front_conn) # frontend qdb_debugger = qdb.Qdb(pipe=child_conn, redirect_stdio=False, skip=None) # backend dbg = qdb_debugger # enable getting context (stack, globals/locals) at interaction qdb_debugger.set_params(dict(call_stack=True, environment=True)) import gluon.main gluon.main.global_settings.debugging = True