diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-07 16:42:20 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-07 16:42:20 +0200 |
commit | e00965c88c3d9ebcd7a639aa643390527c2ae60d (patch) | |
tree | 365a9f149eeff3214fe899cc964df1d83c612333 /wee_slack.py | |
parent | 3b6738ba91a000c38fe765962c2cbee8cb590e59 (diff) | |
download | wee-slack-e00965c88c3d9ebcd7a639aa643390527c2ae60d.tar.gz |
Prevent websocket-client from importing and using numpy
This prevents a crash when you reload the script when using python 3 if
numpy is installed. When weechat unloads a script it calls Py_Finalize,
and when it loads a script, it calls Py_Initialize. If numpy is
imported, this causes python to segfault, which crashes weechat.
By setting numpy in sys.modules to None, it won't be imported when
websocket-client tries to import it. numpy is an optional dependency of
websocket-client, and if it's not installed, it will set numpy to None
itself, so therefore, this should work just like when numpy isn't
installed.
See https://github.com/numpy/numpy/issues/11925 for more details about
the issue in numpy.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py index 4ac73c4..b6a3393 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -25,6 +25,11 @@ import random import socket import string +# Prevent websocket from using numpy (it's an optional dependency). We do this +# because numpy causes python (and thus weechat) to crash when it's reloaded. +# See https://github.com/numpy/numpy/issues/11925 +sys.modules["numpy"] = None + from websocket import ABNF, create_connection, WebSocketConnectionClosedException try: |