Skip to content

Commit c57a032

Browse files
authored
Merge pull request #2 from cocolato/dev
Add README && LICENSE
2 parents aec2112 + b1e1ffe commit c57a032

File tree

6 files changed

+235
-2
lines changed

6 files changed

+235
-2
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
The MIT License (MIT)
3+
Copyright (C) 2022 cocolato <[email protected]>
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
THE SOFTWARE.
19+
"""

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Python post-mortem debugging
2+
3+
English | [简体中文](README_zh.md)
4+
5+
It's a fork/optimized version from [elifiner/pydump](https://github.com/elifiner/pydump).The main optimization points are:
6+
* Optimize code structure && remove redundant code
7+
* fix bug in python2.7 && support python3.10+
8+
* supported more pdb commnd
9+
10+
11+
Pydump writes the traceback of an exception into a file and
12+
can later load it in a Python debugger. It works with the built-in
13+
pdb and with other popular debuggers (pudb, ipdb and pdbpp).
14+
15+
## Why use pydumpling?
16+
17+
* We usually use `try... except ... ` to catch exceptions that occur in our programs, but do we really know why they occur?
18+
* When your project is running online, you suddenly get an unexpected exception that causes the process to exit. How do you reproduce this problem?
19+
* Not enough information in the logs to help us pinpoint online issues?
20+
* If we were able to save the exception error and then use the debugger to recover the traceback at that time, we could see the entire stack variables along the traceback as if you had caught the exception at the local breakpoint.
21+
22+
## Install pydumpling
23+
Python version:>= 2.7, >=3.6
24+
25+
Not published in pypi,so use the `.whl` file install pydumpling in the dist path.
26+
```
27+
pip install dist/pydumpling-0.1.0-py2.py3-none-any.whl
28+
```
29+
30+
## How to use pydumpling
31+
32+
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`.
33+
34+
```python
35+
from pydumpling import save_dumping
36+
37+
def inner():
38+
a = 1
39+
b = "2"
40+
c = a + b
41+
42+
43+
def outer():
44+
inner()
45+
46+
47+
if __name__ == "__main__":
48+
try:
49+
outer()
50+
except Exception:
51+
save_dumping("test.dump")
52+
53+
```
54+
55+
Now we have the `test.dump` file, which we can use `debub_dumpling` to do pdb debug:
56+
```python
57+
Python 3.10.6 (main, Aug 1 2022, 20:38:21) [GCC 5.4.0 20160609] on linux
58+
Type "help", "copyright", "credits" or "license" for more information.
59+
>>> from pydumpling import debug_dumpling
60+
>>> debug_dumpling("test.dump")
61+
> /home/loyd/vscodeFiles/pydumpling/test.py(6)inner()
62+
-> c = a + b
63+
(Pdb) lsit 1,17
64+
*** SyntaxError: invalid syntax
65+
(Pdb) list 1,17
66+
1 from pydumpling import save_dumping
67+
2
68+
3 def inner():
69+
4 >> a = 1
70+
5 b = "2"
71+
6 -> c = a + b
72+
7
73+
8
74+
9 def outer():
75+
10 inner()
76+
11
77+
12
78+
13 if __name__ == "__main__":
79+
14 try:
80+
15 outer()
81+
16 except Exception:
82+
17 save_dumping("test.dump")
83+
(Pdb) ll
84+
3 def inner():
85+
4 >> a = 1
86+
5 b = "2"
87+
6 -> c = a + b
88+
(Pdb) bt
89+
/home/loyd/vscodeFiles/pydumpling/test.py(15)<module>()
90+
-> outer()
91+
/home/loyd/vscodeFiles/pydumpling/test.py(10)outer()
92+
-> inner()
93+
> /home/loyd/vscodeFiles/pydumpling/test.py(6)inner()
94+
-> c = a + b
95+
(Pdb) pp a
96+
1
97+
(Pdb) pp b
98+
'2'
99+
(Pdb) u
100+
> /home/loyd/vscodeFiles/pydumpling/test.py(10)outer()
101+
-> inner()
102+
(Pdb) ll
103+
9 def outer():
104+
10 -> inner()
105+
(Pdb)
106+
```
107+
## TODO
108+
- []

README_zh.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# 针对Python的异常调试器
2+
3+
这是 [elifiner/pydump](https://github.com/elifiner/pydump) 的fork/优化版本, 主要优化点有:
4+
* 优化代码结构, 去除冗余代码
5+
* 修复其在2.7及3.10版本中的bug
6+
* 支持更多的pdb命令
7+
8+
pydump可以在程序抛出异常时,将异常的traceback写到一个文件中,可以稍后在Python调试器中加载它。目前pydump支持很多兼容PDB api的调试器(pdbpp, udb, ipdb)
9+
10+
## 为什么会有Pydump?
11+
12+
* 我们在日常代码编写中,通常都会用`try ... except ...`去捕获程序中出现的异常,但是我们真的知道这些异常出现的原因吗?
13+
* 当你的项目在线上运行时,突然出现了不符合预期的异常导致进程退出,你应该怎样去复现当时的异常现场?
14+
* 日志中没有足够的信息帮助我们去准确定位线上问题?
15+
* 如果我们能够把线上的异常现场保存下来,然后通过调试器去恢复当时的异常堆栈,我们可以看到这个异常的整条调用链路以及链路上的堆栈变量,就如同你在本地断点捕获到了这个异常一样。
16+
17+
## 安装方法
18+
Python版本支持:>= 2.7, >=3.6
19+
20+
目前还没有在Pypi上面进行发布,因此直接使用PIP安装dist目录下的whl文件
21+
```
22+
pip install dist/pydumpling-0.1.0-py2.py3-none-any.whl
23+
```
24+
25+
## 使用方法
26+
27+
In the code, find the place where we need to do the exception replump and use 'save_dumpling()'. When we save the dump file, it will default to '${exception file}:${line number of the exception}.dump'.
28+
29+
```python
30+
from pydumpling import save_dumping
31+
32+
def inner():
33+
a = 1
34+
b = "2"
35+
c = a + b
36+
37+
38+
def outer():
39+
inner()
40+
41+
42+
if __name__ == "__main__":
43+
try:
44+
outer()
45+
except Exception:
46+
save_dumping("test.dump")
47+
48+
```
49+
50+
这样我们就得到了当时异常`traceback``dump文件`,通过`debub_dumpling`即可对其进行pdb调试:
51+
52+
```python
53+
Python 3.10.6 (main, Aug 1 2022, 20:38:21) [GCC 5.4.0 20160609] on linux
54+
Type "help", "copyright", "credits" or "license" for more information.
55+
>>> from pydumpling import debug_dumpling
56+
>>> debug_dumpling("test.dump")
57+
> /home/loyd/vscodeFiles/pydumpling/test.py(6)inner()
58+
-> c = a + b
59+
(Pdb) lsit 1,17
60+
*** SyntaxError: invalid syntax
61+
(Pdb) list 1,17
62+
1 from pydumpling import save_dumping
63+
2
64+
3 def inner():
65+
4 >> a = 1
66+
5 b = "2"
67+
6 -> c = a + b
68+
7
69+
8
70+
9 def outer():
71+
10 inner()
72+
11
73+
12
74+
13 if __name__ == "__main__":
75+
14 try:
76+
15 outer()
77+
16 except Exception:
78+
17 save_dumping("test.dump")
79+
(Pdb) ll
80+
3 def inner():
81+
4 >> a = 1
82+
5 b = "2"
83+
6 -> c = a + b
84+
(Pdb) bt
85+
/home/loyd/vscodeFiles/pydumpling/test.py(15)<module>()
86+
-> outer()
87+
/home/loyd/vscodeFiles/pydumpling/test.py(10)outer()
88+
-> inner()
89+
> /home/loyd/vscodeFiles/pydumpling/test.py(6)inner()
90+
-> c = a + b
91+
(Pdb) pp a
92+
1
93+
(Pdb) pp b
94+
'2'
95+
(Pdb) u
96+
> /home/loyd/vscodeFiles/pydumpling/test.py(10)outer()
97+
-> inner()
98+
(Pdb) ll
99+
9 def outer():
100+
10 -> inner()
101+
(Pdb)
102+
```
103+
104+
## TODO
105+
- []
4.35 KB
Binary file not shown.

dist/pydumpling-0.1.0.tar.gz

3.51 KB
Binary file not shown.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ version = "0.1.0"
44
description = ""
55
authors = ["cocolato <[email protected]>"]
66
readme = "README.md"
7+
packages = [{include = "pydumpling/*.py"}]
78

89
[tool.poetry.dependencies]
9-
python = "^3.10"
10-
dill = "^0.3.6"
10+
python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
11+
dill = "^0.3.2"
1112
six = "^1.16.0"
1213

1314

0 commit comments

Comments
 (0)