|
1 | 1 | import atexit
|
2 | 2 | import logging
|
| 3 | +import os |
3 | 4 | import signal
|
4 |
| -import socket |
5 | 5 | from pathlib import Path
|
6 | 6 |
|
7 | 7 | from . import IS_MACOS, IS_WIDOWS
|
@@ -363,20 +363,20 @@ def reset_window_position(self):
|
363 | 363 | self.setGeometry(QRect(*top_left + geometry))
|
364 | 364 |
|
365 | 365 | 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) |
368 | 372 | # 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) |
371 | 374 | signal.signal(OUR_SIGUSR1, lambda sig, frame: None)
|
372 |
| - # Avoid ResourceWarning on exit |
373 |
| - atexit.register(rsock.close) |
374 |
| - atexit.register(wsock.close) |
375 | 375 |
|
376 | 376 | def sigusr1_received():
|
377 |
| - nonlocal notifier, self, rsock |
| 377 | + nonlocal notifier, self, r_fd |
378 | 378 | notifier.setEnabled(False)
|
379 |
| - signum = ord(rsock.recv(1)) |
| 379 | + signum = ord(os.read(r_fd, 1)) |
380 | 380 | if signum == OUR_SIGUSR1:
|
381 | 381 | logger.info('Handled SIGUSR1. Showing up!')
|
382 | 382 | self.reset_window_position()
|
|
0 commit comments