Commit 321b0bf8 by Julien Muchembled

Update neo/debug.py example

parent e5c056b9
...@@ -12,12 +12,15 @@ The prompt is accessible through network in case that the process is daemonized: ...@@ -12,12 +12,15 @@ The prompt is accessible through network in case that the process is daemonized:
IF = 'pdb' IF = 'pdb'
if IF == 'pdb': if IF == 'pdb':
import socket, sys, threading import socket, sys, threading
from neo.lib.debug import getPdb # Unfortunately, IPython does not always print to given stdout.
#from pdb import Pdb as getPdb #from neo.lib.debug import getPdb
from pdb import Pdb as getPdb
class Socket(object): class Socket(object):
def __init__(self, socket): def __init__(self, socket):
# In case that the default timeout is not None.
socket.settimeout(None)
self._socket = socket self._socket = socket
self._buf = '' self._buf = ''
...@@ -55,9 +58,12 @@ if IF == 'pdb': ...@@ -55,9 +58,12 @@ if IF == 'pdb':
def pdb(app_set): def pdb(app_set):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: try:
# For better security, maybe we should use a unix socket.
s.settimeout(60)
s.bind(('127.0.0.1', 0)) s.bind(('127.0.0.1', 0))
s.listen(0) s.listen(0)
print 'Listening to %u' % s.getsockname()[1] print 'Listening to %u' % s.getsockname()[1]
sys.stdout.flush() # BBB: On Python 3, print() takes a 'flush' arg.
_socket = Socket(s.accept()[0]) _socket = Socket(s.accept()[0])
finally: finally:
s.close() s.close()
...@@ -69,7 +75,7 @@ if IF == 'pdb': ...@@ -69,7 +75,7 @@ if IF == 'pdb':
app # this is Application instance (see 'app_set' if there are several) app # this is Application instance (see 'app_set' if there are several)
try: try:
app_set = sys.modules['neo.client.app'].app_set app_set = sys.modules['neo.lib.threaded_app'].app_set
except KeyError: except KeyError:
f = sys._getframe(3) f = sys._getframe(3)
try: try:
......
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 sign in to comment