diff options
author | linuxdaemon <linuxdaemon@users.noreply.github.com> | 2018-12-27 13:46:02 -0600 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2018-12-27 14:46:02 -0500 |
commit | a5a727122b66c9003b44fcdc199ad56dbe15a131 (patch) | |
tree | 63a33c65a4c266962ede9f9b186f62a4ddd7e532 | |
parent | f7713a6a64ee55d3c20e9e27b8f8a5e98385ff57 (diff) |
python: Make sure `help()` doesn't cause hexchat to hang (#2290)
* Make sure `help()` doesn't cause hexchat to hang Replace `pydoc.help` with a copy of `pydoc.Helper` with an empty `StringIO` instead of stdin * Handle BytesIO vs StringIO on 2.7
-rw-r--r-- | plugins/python/python.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/plugins/python/python.py b/plugins/python/python.py index 371fbf40..1afb36c4 100644 --- a/plugins/python/python.py +++ b/plugins/python/python.py @@ -1,6 +1,7 @@ from __future__ import print_function import os +import pydoc import sys from contextlib import contextmanager import importlib @@ -8,6 +9,12 @@ import signal import site import traceback import weakref + +if sys.version_info < (3, 0): + from io import BytesIO as HelpEater +else: + from io import StringIO as HelpEater + from _hexchat_embedded import ffi, lib if not hasattr(sys, 'argv'): @@ -57,7 +64,6 @@ class Stdout: self.buffer += string def isatty(self): - # FIXME: help() locks app despite this? return False @@ -474,6 +480,7 @@ def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir): hexchat_stdout = Stdout() sys.stdout = hexchat_stdout sys.stderr = hexchat_stdout + pydoc.help = pydoc.Helper(HelpEater(), HelpEater()) lib.hexchat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL, ffi.NULL) lib.hexchat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command, ffi.NULL, ffi.NULL) @@ -505,6 +512,7 @@ def _on_plugin_deinit(): hexchat_stdout = None sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ + pydoc.help = pydoc.Helper() for mod in ('_hexchat', 'hexchat', 'xchat', '_hexchat_embedded'): try: |