Commit 9e026d08 authored by Julien Muchembled's avatar Julien Muchembled

Fix neo/debug.py example for clients

parent e03a836a
...@@ -11,8 +11,8 @@ The prompt is accessible through network in case that the process is daemonized: ...@@ -11,8 +11,8 @@ The prompt is accessible through network in case that the process is daemonized:
if 1: if 1:
import socket, sys, threading import socket, sys, threading
#from neo.lib.debug import getPdb from neo.lib.debug import getPdb
from pdb import Pdb as getPdb #from pdb import Pdb as getPdb
class Socket(object): class Socket(object):
...@@ -51,7 +51,7 @@ if 1: ...@@ -51,7 +51,7 @@ if 1:
self._socket.setblocking(1) self._socket.setblocking(1)
return False return False
def pdb(app): def pdb(app_set):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: try:
s.bind(('127.0.0.1', 0)) s.bind(('127.0.0.1', 0))
...@@ -60,14 +60,24 @@ if 1: ...@@ -60,14 +60,24 @@ if 1:
_socket = Socket(s.accept()[0]) _socket = Socket(s.accept()[0])
finally: finally:
s.close() s.close()
try:
app, = app_set
except ValueError:
app = None
getPdb(stdin=_socket, stdout=_socket).set_trace() getPdb(stdin=_socket, stdout=_socket).set_trace()
app # this is Application instance app # this is Application instance (see 'app_set' if there are several)
f = sys._getframe(3)
try: try:
while f.f_code.co_name != 'run' or \ app_set = sys.modules['neo.client.app'].app_set
f.f_locals.get('self').__class__.__name__ != 'Application': except KeyError:
f = f.f_back f = sys._getframe(3)
threading.Thread(target=pdb, args=(f.f_locals['self'],)).start() try:
finally: while f.f_code.co_name != 'run' or \
del f f.f_locals.get('self').__class__.__name__ != 'Application':
f = f.f_back
app_set = f.f_locals['self'],
except AttributeError:
app_set = ()
finally:
del f
threading.Thread(target=pdb, args=(app_set,)).start()
...@@ -44,14 +44,14 @@ def debugHandler(sig, frame): ...@@ -44,14 +44,14 @@ def debugHandler(sig, frame):
neo.__path__) neo.__path__)
imp.load_module('neo.debug', file, filename, (suffix, mode, type)) imp.load_module('neo.debug', file, filename, (suffix, mode, type))
def getPdb(): def getPdb(**kw):
try: # try ipython if available try: # try ipython if available
import IPython import IPython
shell = IPython.terminal.embed.InteractiveShellEmbed() shell = IPython.terminal.embed.InteractiveShellEmbed()
return IPython.core.debugger.Pdb(shell.colors) return IPython.core.debugger.Pdb(shell.colors, **kw)
except (AttributeError, ImportError): except (AttributeError, ImportError):
import pdb import pdb
return pdb.Pdb() return pdb.Pdb(**kw)
_debugger = None _debugger = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment