Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trio and PyCharm fighting over sys.excepthook #1553

Closed
ernestum opened this issue May 25, 2020 · 12 comments
Closed

Trio and PyCharm fighting over sys.excepthook #1553

ernestum opened this issue May 25, 2020 · 12 comments

Comments

@ernestum
Copy link

The Apport error reporting mechanism of Ubuntu as well as PyCharm register custom sys.excepthooks. 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?

@tjstum
Copy link
Member

tjstum commented May 26, 2020

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?

@tjstum
Copy link
Member

tjstum commented May 26, 2020

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.

@njsmith njsmith changed the title The sys.excepthook mechanism should not collide with others such as the one from Apport or PyCharm Trio and PyCharm fighting over sys.excepthook May 26, 2020
@njsmith
Copy link
Member

njsmith commented May 26, 2020

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__))

?

@mozesa
Copy link

mozesa commented May 26, 2020

<built-in function excepthook>
<built-in function excepthook>

Process finished with exit code 0

I hope it helped.

@njsmith
Copy link
Member

njsmith commented May 26, 2020 via email

@mozesa
Copy link

mozesa commented May 26, 2020

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)

@tjstum
Copy link
Member

tjstum commented May 27, 2020

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.

@mozesa
Copy link

mozesa commented May 27, 2020

Yes it is true, in debug, always there is the warning.

@njsmith
Copy link
Member

njsmith commented May 27, 2020

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.

@dhirschfeld
Copy link
Member

I have also noticed this warning in PyCharm but have so far ignored it 😬

@honglei
Copy link

honglei commented Jul 9, 2022

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

@Zac-HD
Copy link
Member

Zac-HD commented Oct 17, 2023

Closing this in favor of agronholm/exceptiongroup#23.

@Zac-HD Zac-HD closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants