diff --git a/kitty/boss.py b/kitty/boss.py index cae0bd8d2..7184a21ab 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -32,7 +32,7 @@ from .session import create_session from .shaders import Sprites, ShaderProgram from .tabs import TabManager, SpecialWindow from .timers import Timers -from .utils import handle_unix_signals, safe_print +from .utils import handle_unix_signals, safe_print, pipe2 def conditional_run(w, i): @@ -77,7 +77,7 @@ class Boss(Thread): self.shutting_down = False self.screen_update_delay = opts.repaint_delay / 1000.0 self.signal_fd = handle_unix_signals() - self.read_wakeup_fd, self.write_wakeup_fd = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) + self.read_wakeup_fd, self.write_wakeup_fd = pipe2() self.read_dispatch_map = {self.signal_fd: self.signal_received, self.read_wakeup_fd: self.on_wakeup} self.all_writers = [] self.timers = Timers() diff --git a/kitty/utils.py b/kitty/utils.py index a539b9032..e3c89f135 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -271,8 +271,22 @@ def parse_color_set(raw): continue +def pipe2(): + try: + read_fd, write_fd = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) + except AttributeError: + import fcntl + read_fd, write_fd = os.pipe() + for fd in (read_fd, write_fd): + flag = fcntl.fcntl(fd, fcntl.F_GETFD) + fcntl.fcntl(fd, fcntl.F_SETFD, flag | fcntl.FD_CLOEXEC) + flag = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NONBLOCK) + return read_fd, write_fd + + def handle_unix_signals(): - read_fd, write_fd = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) + read_fd, write_fd = pipe2() for sig in (signal.SIGINT, signal.SIGTERM): signal.signal(sig, lambda x, y: None) signal.siginterrupt(sig, False)