Skip to content

Commit 7277e6e

Browse files
committed
Use os.pipe() socket pair for Widows/macOS
1 parent d698fa8 commit 7277e6e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

efck/gui.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import atexit
22
import logging
3+
import os
34
import signal
4-
import socket
55
from pathlib import Path
66

77
from . import IS_MACOS, IS_WIDOWS
@@ -363,20 +363,20 @@ def reset_window_position(self):
363363
self.setGeometry(QRect(*top_left + geometry))
364364

365365
def install_sigusr1_handler(self):
366-
self._socket_pair = (rsock, wsock) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
367-
self._notifier = notifier = QSocketNotifier(rsock.fileno(), QSocketNotifier.Type.Read, self)
366+
r_fd, w_fd = os.pipe()
367+
if not IS_WIDOWS:
368+
os.set_blocking(w_fd, False)
369+
atexit.register(os.close, r_fd)
370+
atexit.register(os.close, w_fd)
371+
self._notifier = notifier = QSocketNotifier(r_fd, QSocketNotifier.Type.Read, self)
368372
# https://stackoverflow.com/questions/4938723/what-is-the-correct-way-to/37229299#37229299
369-
wsock.setblocking(False)
370-
signal.set_wakeup_fd(wsock.fileno())
373+
signal.set_wakeup_fd(w_fd)
371374
signal.signal(OUR_SIGUSR1, lambda sig, frame: None)
372-
# Avoid ResourceWarning on exit
373-
atexit.register(rsock.close)
374-
atexit.register(wsock.close)
375375

376376
def sigusr1_received():
377-
nonlocal notifier, self, rsock
377+
nonlocal notifier, self, r_fd
378378
notifier.setEnabled(False)
379-
signum = ord(rsock.recv(1))
379+
signum = ord(os.read(r_fd, 1))
380380
if signum == OUR_SIGUSR1:
381381
logger.info('Handled SIGUSR1. Showing up!')
382382
self.reset_window_position()

0 commit comments

Comments
 (0)