From 628246c3da7f6105a16b38bb266f748145ae3a0d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 13 Jun 2022 19:22:37 +0530 Subject: [PATCH] Workaround for python 3.8 that doesnt have the CLD_* constants --- kitty/child.c | 4 ++++ kitty/fast_data_types.pyi | 4 ++++ kitty_tests/prewarm.py | 14 +++++++------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kitty/child.c b/kitty/child.c index d1b760216..5d6c71349 100644 --- a/kitty/child.c +++ b/kitty/child.c @@ -210,6 +210,10 @@ static PyMethodDef module_methods[] = { bool init_child(PyObject *module) { + PyModule_AddIntMacro(module, CLD_KILLED); + PyModule_AddIntMacro(module, CLD_STOPPED); + PyModule_AddIntMacro(module, CLD_EXITED); + PyModule_AddIntMacro(module, CLD_CONTINUED); if (PyModule_AddFunctions(module, module_methods) != 0) return false; return true; } diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index d4f121842..5f26de641 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -12,6 +12,10 @@ from kitty.marks import MarkerFunc from kitty.options.types import Options # Constants {{{ +CLD_KILLED: int +CLD_STOPPED: int +CLD_CONTINUED: int +CLD_EXITED: int SHM_NAME_MAX: int MOUSE_SELECTION_LINE: int MOUSE_SELECTION_EXTEND: int diff --git a/kitty_tests/prewarm.py b/kitty_tests/prewarm.py index bb158f66c..5c479008a 100644 --- a/kitty_tests/prewarm.py +++ b/kitty_tests/prewarm.py @@ -10,7 +10,8 @@ import tempfile from kitty.constants import is_macos, kitty_exe from kitty.fast_data_types import ( - get_options, install_signal_handlers, read_signals, remove_signal_handlers + CLD_CONTINUED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, get_options, + install_signal_handlers, read_signals, remove_signal_handlers ) from . import BaseTest @@ -69,7 +70,7 @@ import os, json; from kitty.utils import *; from kitty.fast_data_types import ge nonlocal found_signal self.ae(siginfo.si_signo, signal.SIGCHLD) self.ae(siginfo.si_code, expecting_code) - if expecting_code in (os.CLD_EXITED, os.CLD_KILLED): + if expecting_code in (CLD_EXITED, CLD_KILLED): p.wait(1) p.stdin.close() found_signal = True @@ -90,11 +91,10 @@ import os, json; from kitty.utils import *; from kitty.fast_data_types import ge signal_read_fd = install_signal_handlers(signal.SIGCHLD)[0] try: poll.register(signal_read_fd, select.POLLIN) - if hasattr(os, 'CLD_STOPPED'): - t(signal.SIGTSTP, os.CLD_STOPPED) - # macOS doesnt send SIGCHLD for SIGCONT. This is not required by POSIX sadly - t(signal.SIGCONT, None if is_macos else os.CLD_CONTINUED) - t(signal.SIGINT, os.CLD_KILLED) + t(signal.SIGTSTP, CLD_STOPPED) + # macOS doesnt send SIGCHLD for SIGCONT. This is not required by POSIX sadly + t(signal.SIGCONT, None if is_macos else CLD_CONTINUED) + t(signal.SIGINT, CLD_KILLED) p = subprocess.Popen([kitty_exe(), '+runpy', 'input()'], stderr=subprocess.DEVNULL, stdin=subprocess.PIPE) p.stdin.close() t(None, os.CLD_EXITED)