Skip to content

Commit e63feff

Browse files
committed
Patch event loop class on Windows so REPL doesn't fail
1 parent 6f87ec8 commit e63feff

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

hippolyzer/apps/proxy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import outleap
1313

1414
from hippolyzer.lib.base import llsd
15+
from hippolyzer.lib.base.helpers import patch_loop_factory_for_ptpython
1516
from hippolyzer.lib.proxy.addons import AddonManager
1617
from hippolyzer.lib.proxy.addon_utils import BaseAddon
1718
from hippolyzer.lib.proxy.ca_utils import setup_ca
@@ -206,6 +207,7 @@ def _windows_timeout_killer(pid: int):
206207

207208

208209
def main():
210+
patch_loop_factory_for_ptpython()
209211
multiprocessing.set_start_method("spawn")
210212
start_proxy(SessionManager(ProxySettings()))
211213

hippolyzer/apps/proxy_gui.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from hippolyzer.apps.proxy import start_proxy
2525
from hippolyzer.lib.base import llsd
2626
from hippolyzer.lib.base.datatypes import UUID
27-
from hippolyzer.lib.base.helpers import bytes_unescape, bytes_escape, get_resource_filename, create_logged_task
27+
from hippolyzer.lib.base.helpers import bytes_unescape, bytes_escape, get_resource_filename, create_logged_task, \
28+
patch_loop_factory_for_ptpython
2829
from hippolyzer.lib.base.message.llsd_msg_serializer import LLSDMessageSerializer
2930
from hippolyzer.lib.base.message.message import Block, Message
3031
from hippolyzer.lib.base.message.message_formatting import (
@@ -924,6 +925,7 @@ def _removeCurrentPressed(self):
924925

925926

926927
def gui_main():
928+
patch_loop_factory_for_ptpython()
927929
multiprocessing.set_start_method('spawn')
928930
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
929931
app = QtWidgets.QApplication(sys.argv)

hippolyzer/lib/base/helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import functools
66
import logging
77
import os
8+
import platform
89

910
import lazy_object_proxy
1011
import pkg_resources
@@ -213,3 +214,17 @@ def reorient_coord(coord, new_orientation, min_val: int | float = 0):
213214
if coord.__class__ in (list, tuple):
214215
return coord.__class__(coords)
215216
return coord.__class__(*coords)
217+
218+
219+
def patch_loop_factory_for_ptpython() -> None:
220+
# This patch can be removed when https://github.com/prompt-toolkit/ptpython/issues/582 is fixed
221+
from asyncio import get_event_loop_policy
222+
if platform.system() != "Windows":
223+
return
224+
225+
policy = get_event_loop_policy()
226+
# Note: this patches the underlying event loop class, already existing subclasses should pick up these
227+
# new additions as well. This is important for the Qt event loops.
228+
if loop_factory := getattr(policy, "_loop_factory", None):
229+
for attr in ("add_signal_handler", "remove_signal_handler"):
230+
setattr(loop_factory, attr, lambda *args, **kwargs: None)

0 commit comments

Comments
 (0)