diff --git a/efck/gui.py b/efck/gui.py index 8a599db..aabc374 100644 --- a/efck/gui.py +++ b/efck/gui.py @@ -1,7 +1,7 @@ import atexit import logging +import os import signal -import socket from pathlib import Path from . import IS_MACOS, IS_WIDOWS @@ -363,20 +363,20 @@ def reset_window_position(self): self.setGeometry(QRect(*top_left + geometry)) def install_sigusr1_handler(self): - self._socket_pair = (rsock, wsock) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0) - self._notifier = notifier = QSocketNotifier(rsock.fileno(), QSocketNotifier.Type.Read, self) + r_fd, w_fd = os.pipe() + if not IS_WIDOWS: + os.set_blocking(w_fd, False) + atexit.register(os.close, r_fd) + atexit.register(os.close, w_fd) + self._notifier = notifier = QSocketNotifier(r_fd, QSocketNotifier.Type.Read, self) # https://stackoverflow.com/questions/4938723/what-is-the-correct-way-to/37229299#37229299 - wsock.setblocking(False) - signal.set_wakeup_fd(wsock.fileno()) + signal.set_wakeup_fd(w_fd) signal.signal(OUR_SIGUSR1, lambda sig, frame: None) - # Avoid ResourceWarning on exit - atexit.register(rsock.close) - atexit.register(wsock.close) def sigusr1_received(): - nonlocal notifier, self, rsock + nonlocal notifier, self, r_fd notifier.setEnabled(False) - signum = ord(rsock.recv(1)) + signum = ord(os.read(r_fd, 1)) if signum == OUR_SIGUSR1: logger.info('Handled SIGUSR1. Showing up!') self.reset_window_position()