Workaround for python 3.8 that doesnt have the CLD_* constants

This commit is contained in:
Kovid Goyal 2022-06-13 19:22:37 +05:30
parent d228acd30a
commit 628246c3da
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 7 deletions

View File

@ -210,6 +210,10 @@ static PyMethodDef module_methods[] = {
bool bool
init_child(PyObject *module) { 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; if (PyModule_AddFunctions(module, module_methods) != 0) return false;
return true; return true;
} }

View File

@ -12,6 +12,10 @@ from kitty.marks import MarkerFunc
from kitty.options.types import Options from kitty.options.types import Options
# Constants {{{ # Constants {{{
CLD_KILLED: int
CLD_STOPPED: int
CLD_CONTINUED: int
CLD_EXITED: int
SHM_NAME_MAX: int SHM_NAME_MAX: int
MOUSE_SELECTION_LINE: int MOUSE_SELECTION_LINE: int
MOUSE_SELECTION_EXTEND: int MOUSE_SELECTION_EXTEND: int

View File

@ -10,7 +10,8 @@ import tempfile
from kitty.constants import is_macos, kitty_exe from kitty.constants import is_macos, kitty_exe
from kitty.fast_data_types import ( 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 from . import BaseTest
@ -69,7 +70,7 @@ import os, json; from kitty.utils import *; from kitty.fast_data_types import ge
nonlocal found_signal nonlocal found_signal
self.ae(siginfo.si_signo, signal.SIGCHLD) self.ae(siginfo.si_signo, signal.SIGCHLD)
self.ae(siginfo.si_code, expecting_code) 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.wait(1)
p.stdin.close() p.stdin.close()
found_signal = True 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] signal_read_fd = install_signal_handlers(signal.SIGCHLD)[0]
try: try:
poll.register(signal_read_fd, select.POLLIN) poll.register(signal_read_fd, select.POLLIN)
if hasattr(os, 'CLD_STOPPED'): t(signal.SIGTSTP, CLD_STOPPED)
t(signal.SIGTSTP, os.CLD_STOPPED) # macOS doesnt send SIGCHLD for SIGCONT. This is not required by POSIX sadly
# 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.SIGCONT, None if is_macos else os.CLD_CONTINUED) t(signal.SIGINT, CLD_KILLED)
t(signal.SIGINT, os.CLD_KILLED)
p = subprocess.Popen([kitty_exe(), '+runpy', 'input()'], stderr=subprocess.DEVNULL, stdin=subprocess.PIPE) p = subprocess.Popen([kitty_exe(), '+runpy', 'input()'], stderr=subprocess.DEVNULL, stdin=subprocess.PIPE)
p.stdin.close() p.stdin.close()
t(None, os.CLD_EXITED) t(None, os.CLD_EXITED)