From a5a727122b66c9003b44fcdc199ad56dbe15a131 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 27 Dec 2018 13:46:02 -0600 Subject: 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 --- plugins/python/python.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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: -- cgit 1.4.1