Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
neoppod
Commits
933953e2
Commit
933953e2
authored
Nov 30, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug: extend 'pdb' example to optionally break on an arbitrary list of callables
parent
ec031cdf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
3 deletions
+57
-3
neo/debug.py
neo/debug.py
+57
-3
No files found.
neo/debug.py
View file @
933953e2
...
...
@@ -11,7 +11,15 @@ The prompt is accessible through network in case that the process is daemonized:
IF
=
'pdb'
if
IF
==
'pdb'
:
import
socket
,
sys
,
threading
# List of (module, callables) to break at.
# If empty, a thread is started with a breakpoint.
# All breakpoints are automatically removed on the first break,
# or when this module is reloaded.
BP
=
(
#('ZODB.Connection', 'Connection.setstate'),
#('ZPublisher.Publish', 'publish_module_standard'),
)
import
errno
,
socket
,
sys
,
threading
,
weakref
# Unfortunately, IPython does not always print to given stdout.
#from neo.lib.debug import getPdb
from
pdb
import
Pdb
as
getPdb
...
...
@@ -55,7 +63,7 @@ if IF == 'pdb':
self
.
_socket
.
setblocking
(
1
)
return
False
def
pdb
(
app_set
):
def
pdb
():
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
# For better security, maybe we should use a unix socket.
...
...
@@ -87,7 +95,53 @@ if IF == 'pdb':
app_set
=
()
finally
:
del
f
threading
.
Thread
(
target
=
pdb
,
args
=
(
app_set
,)).
start
()
class
setupBreakPoints
(
list
):
def
__init__
(
self
,
bp_list
):
self
.
_lock
=
threading
.
Lock
()
for
o
,
name
in
bp_list
:
o
=
__import__
(
o
,
fromlist
=
1
)
x
=
name
.
split
(
'.'
)
name
=
x
.
pop
()
for
x
in
x
:
o
=
getattr
(
o
,
x
)
orig
=
getattr
(
o
,
name
)
if
orig
.
__module__
==
__name__
:
orig
.
__closure__
[
1
].
cell_contents
.
_revert
()
orig
=
getattr
(
o
,
name
)
assert
orig
.
__module__
!=
__name__
,
(
o
,
name
)
orig
=
getattr
(
orig
,
'__func__'
,
orig
)
self
.
append
((
o
,
name
,
orig
))
setattr
(
o
,
name
,
self
.
_wrap
(
orig
))
print
'BP set on'
,
orig
sys
.
stdout
.
flush
()
self
.
_hold
=
weakref
.
ref
(
pdb
,
self
.
_revert
)
def
_revert
(
self
,
*
_
):
for
x
in
self
:
setattr
(
*
x
)
print
'BP removed on'
,
x
[
2
]
sys
.
stdout
.
flush
()
del
self
[:]
def
_wrap
(
self
,
orig
):
return
lambda
*
args
,
**
kw
:
self
(
orig
,
*
args
,
**
kw
)
def
__call__
(
self
,
orig
,
*
args
,
**
kw
):
stop
=
False
with
self
.
_lock
:
if
self
:
stop
=
True
self
.
_revert
()
if
stop
:
pdb
()
return
orig
(
*
args
,
**
kw
)
if
BP
:
setupBreakPoints
(
BP
)
else
:
threading
.
Thread
(
target
=
pdb
).
start
()
elif
IF
==
'frames'
:
import
sys
,
traceback
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment