trio
trio copied to clipboard
Trio and PyCharm fighting over sys.excepthook
The Apport error reporting mechanism of Ubuntu as well as PyCharm register custom sys.excepthook
s. This causes the warning:
trio/_core/_multierror.py:472: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
and prevents uncaught multierrors from being printed properly.
I can reproduce this problem by simply running the following test.pyt
:
import trio
from within PyCharm or on any Ubuntu/Mint machine that has the python3-apport
packet installed.
A possible workaround is to run sys.excepthook = sys.__excepthook__
before importing trio but then the functionality of Apport/PyCharm will probably break.
Unfortunately there is no way to register multiple excepthooks in Python. However we might be able to "wrap" existing excepthooks instead of giving up in desparation?
Hi!
Thanks for this detailed report. This was recently fixed (original issue #1065, fixed in #1528). This was included in the release 0.15.0 (and subsequent 0.15.1). Are you still seeing this issue even on the latest release?
Oh, I guess you also described an issue with PyCharm's excepthook! Maybe we should leave this open but rename/change the summary to narrow the scope.
Yeah, can you give more details on the PyCharm issue?
In PyCharm, what do you get if you do:
print(repr(sys.excepthook))
print(repr(sys.__excepthook__))
?
<built-in function excepthook>
<built-in function excepthook>
Process finished with exit code 0
I hope it helped.
Huh. And what do you get from 'print(sys.excepthook is sys.excepthook)'?
On Mon, May 25, 2020, 22:50 András Mózes [email protected] wrote:
Process finished with exit code 0
I hope it helped.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-trio/trio/issues/1553#issuecomment-633820405, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEU42BRFGTPG5BFTI3G7H3RTNKB3ANCNFSM4NJR55HA .
I made a big misstake :(
import sys
import trio
print(repr(sys.excepthook))
print(repr(sys.__excepthook__))
<function trio_excepthook at 0x0000026AC55BE5E0>
<built-in function excepthook>
and now print(sys.excepthook is sys.__excepthook__)
is False
(previously I didn't import trio
)
I was able to reproduce this using PyCharm. You have to use PyCharm's "debug" feature, not the normal "run" command:
Connected to pydev debugger (build 201.7223.92)
/.../site-packages/trio/_core/_multierror.py:472: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
category=RuntimeWarning
<function _fallback_excepthook at 0x7fa29db23840>
<built-in function excepthook>
I think this is their excepthook.
Yes it is true, in debug, always there is the warning.
Well, adding special monkeypatches for each random library is obviously a terrible long-term approach. But in the short term, that looks like a pretty easy special monkeypatch to do. Something like: check for the PyCharm excepthook, and if it's found then monkeypatch the default_excepthook
variable inside that module.
I have also noticed this warning in PyCharm but have so far ignored it 😬
same warning for WingPro8, just ignore it.
C:\Python310\lib\site-packages\trio\_core\_multierror.py:511: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
warnings.warn(
<bound method CWhenPrintExceptionSupport.__ExceptHook of <debug.tserver.dbgutils.CWhenPrintExceptionSupport object at 0x000001D295CE65C0>>
<built-in function excepthook>
False
Closing this in favor of https://github.com/agronholm/exceptiongroup/issues/23.