Skip to content

Commit 0f0fb11

Browse files
authored
Merge pull request #31 from cocolato/dev
support catch_any_exception
2 parents ebd7f84 + 5d3bb36 commit 0f0fb11

File tree

10 files changed

+99
-22
lines changed

10 files changed

+99
-22
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def outer():
5353

5454
### Save the exception traceback.
5555

56-
In the code, find the place where we need to do the `try ... except ...` and use `save_dumpling()`. When we save the dump file, it will default to `${exception filename}:${error lineno}.dump`.
56+
In the code, find the place where we need to do the `try ... except ...` and use `save_dumpling()`. When we save the dump file, it will default to `${exception filename}-${error lineno}.dump`.
5757

5858
```python
5959
from pydumpling import save_dumping
@@ -160,5 +160,25 @@ It will open the debugger on port 4444, then we can access pdb using telnet、ne
160160
`nc 127.0.0.1 4444`
161161
![alt text](static/rpdb.png)
162162

163+
#### Enable global exception catching:
164+
```python
165+
from pydumpling import catch_any_exception
166+
167+
catch_any_exception()
168+
169+
def inner():
170+
a = 1
171+
b = "2"
172+
c = a + b # noqa: F841
173+
174+
175+
def outer():
176+
inner()
177+
178+
if __name__ == "__main__":
179+
outer()
180+
181+
```
182+
163183
## TODO
164184
- []

README_zh.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def outer():
4848

4949

5050
### 在异常发生时进行异常堆栈的保存
51-
在异常捕获的处理代码中使用`save_dumpling()`. 如果不指定文件名,默认使用:`${exception file}:${line number of the exception}.dump`.
51+
在异常捕获的处理代码中使用`save_dumpling()`. 如果不指定文件名,默认使用:`${exception file}-${line number of the exception}.dump`.
5252

5353
```python
5454
from pydumpling import save_dumping
@@ -156,5 +156,25 @@ TypeError: unsupported operand type(s) for +: 'int' and 'str'
156156
`nc 127.0.0.1 4444`
157157
![alt text](static/rpdb.png)
158158

159+
#### 开启全局异常捕获:
160+
```python
161+
from pydumpling import catch_any_exception
162+
163+
catch_any_exception()
164+
165+
def inner():
166+
a = 1
167+
b = "2"
168+
c = a + b # noqa: F841
169+
170+
171+
def outer():
172+
inner()
173+
174+
if __name__ == "__main__":
175+
outer()
176+
177+
```
178+
159179
## TODO
160180
- []

docs/source/tutorial.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ help message
122122
-h, --help show this help message and exit
123123
--print print traceback information
124124
--debug enter pdb debugging interface
125+
--rdebug enter rpdb debugging interface
125126
126127
Print the traceback
127128
###################
@@ -164,4 +165,27 @@ It will open the debugger on port 4444, then we can access pdb using `telnet`_,
164165
.. _netcat: https://netcat.sourceforge.net/
165166

166167

167-
.. image:: _static/rpdb.png
168+
.. image:: _static/rpdb.png
169+
170+
171+
Enable global exception catching
172+
################################
173+
174+
.. code-block:: python
175+
176+
from pydumpling import catch_any_exception
177+
178+
catch_any_exception()
179+
180+
def inner():
181+
a = 1
182+
b = "2"
183+
c = a + b # noqa: F841
184+
185+
186+
def outer():
187+
inner()
188+
189+
if __name__ == "__main__":
190+
outer()
191+

pydumpling/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from __future__ import absolute_import, division, print_function, unicode_literals
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
23

3-
from .rpdb import r_post_mortem
44
from .debug_dumpling import debug_dumpling, load_dumpling
5-
from .pydumpling import save_dumping, dump_current_traceback, __version__
6-
5+
from .helpers import catch_any_exception
6+
from .pydumpling import __version__, dump_current_traceback, save_dumping
7+
from .rpdb import r_post_mortem
78

89
__version__ == __version__
9-
__all__ = ["debug_dumpling", "load_dumpling", "save_dumping", "dump_current_traceback", "r_post_mortem"]
10+
__all__ = ["debug_dumpling", "load_dumpling", "save_dumping",
11+
"dump_current_traceback", "r_post_mortem", "catch_any_exception"]

pydumpling/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import argparse
22
import os.path
3+
34
from .debug_dumpling import debug_dumpling, load_dumpling
4-
from .rpdb import r_post_mortem
55
from .helpers import print_traceback_and_except
6+
from .rpdb import r_post_mortem
67

78
DUMP_FILE_EXTENSION: str = ".dump"
89

pydumpling/debug_dumpling.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
from __future__ import absolute_import, division, print_function, unicode_literals
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
23

34
import gzip
5+
import inspect
46
import pdb
5-
import dill
67
import pickle
7-
from packaging.version import parse
8-
import inspect
98
import types
10-
from .fake_types import FakeFrame, FakeTraceback, FakeCode
9+
10+
import dill
11+
from packaging.version import parse
12+
13+
from .fake_types import FakeCode, FakeFrame, FakeTraceback
1114

1215

1316
def load_dumpling(filename):

pydumpling/fake_types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from __future__ import absolute_import, division, print_function, unicode_literals
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
23

34
import os
45
import sys
6+
57
import dill
68

79

@@ -41,7 +43,7 @@ def _convert(cls, v):
4143
except Exception:
4244
return cls._safe_repr(v)
4345
else:
44-
from datetime import date, time, datetime, timedelta
46+
from datetime import date, datetime, time, timedelta
4547

4648
BUILTIN = (str, unicode, int, long, float, date, time, datetime, timedelta) if sys.version_info.major == 2 \
4749
else (str, int, float, date, time, datetime, timedelta) # noqa: F821

pydumpling/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
2-
from traceback import print_tb, print_exception
2+
from traceback import print_exception, print_tb
3+
34
from .pydumpling import save_dumping
45

56

pydumpling/pydumpling.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from __future__ import absolute_import, division, print_function, unicode_literals
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
23

34
import gzip
4-
import sys
5-
import dill
5+
import inspect
66
import pickle
7+
import sys
78
import warnings
8-
import inspect
9+
10+
import dill
11+
912
from .fake_types import FakeFrame, FakeTraceback
1013

1114
__version__ = "0.1.5"

pydumpling/rpdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pdb
22
import socket
3-
import threading
43
import sys
4+
import threading
5+
56
from .debug_dumpling import load_dumpling, mock_inspect
67

78
DEFAULT_ADDR = "127.0.0.1"

0 commit comments

Comments
 (0)