Skip to content

Commit 7a27c7c

Browse files
woutdenolfauvipy
authored andcommitted
ExceptionInfo.exception should be an exception
1 parent 69c576d commit 7a27c7c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

billiard/einfo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,24 @@ def __init__(self, tb, max_frames=DEFAULT_MAX_FRAMES, depth=0):
9191
class RemoteTraceback(Exception):
9292
def __init__(self, tb):
9393
self.tb = tb
94+
9495
def __str__(self):
9596
return self.tb
9697

97-
class ExceptionWithTraceback:
98+
99+
class ExceptionWithTraceback(Exception):
98100
def __init__(self, exc, tb):
99101
self.exc = exc
100102
self.tb = '\n"""\n%s"""' % tb
103+
super().__init__()
104+
105+
def __str__(self):
106+
return self.tb
107+
101108
def __reduce__(self):
102109
return rebuild_exc, (self.exc, self.tb)
103110

111+
104112
def rebuild_exc(exc, tb):
105113
exc.__cause__ = RemoteTraceback(tb)
106114
return exc

t/unit/test_einfo.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pickle
2+
import logging
3+
from billiard.einfo import ExceptionInfo
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
def test_exception_info_log_before_pickle(caplog):
9+
try:
10+
raise RuntimeError("some message")
11+
except Exception:
12+
exception = ExceptionInfo().exception
13+
14+
logger.exception("failed", exc_info=exception)
15+
assert ' raise RuntimeError("some message")' in caplog.text
16+
assert "RuntimeError: some message" in caplog.text
17+
18+
19+
def test_exception_info_log_after_pickle(caplog):
20+
try:
21+
raise RuntimeError("some message")
22+
except Exception:
23+
exception = ExceptionInfo().exception
24+
exception = pickle.loads(pickle.dumps(exception))
25+
26+
logger.exception("failed", exc_info=exception)
27+
assert ' raise RuntimeError("some message")' in caplog.text
28+
assert "RuntimeError: some message" in caplog.text

0 commit comments

Comments
 (0)