Also catch SIGBREAK on windows, and remove useless code

This commit is contained in:
Mariano Sorgente 2020-08-17 22:42:24 +09:00 committed by Gene Hoffman
parent 7c777b0fd3
commit 5b27140b0c
2 changed files with 4 additions and 24 deletions

View File

@ -5,12 +5,10 @@ https://stackoverflow.com/questions/35772001/how-to-handle-the-signal-in-python-
import os
import sys
import time
import signal
if sys.platform != "win32" and sys.platform != "cygwin":
kill = os.kill
sleep = time.sleep
else:
# adapt the conflated API on Windows.
import threading
@ -53,25 +51,3 @@ else:
signal.signal(signum, handler)
else:
os.kill(pid, sigmap.get(signum, signum))
if sys.version_info[0] > 2:
sleep = time.sleep
else:
import errno
# If the signal handler doesn't raise an exception,
# time.sleep in Python 2 raises an EINTR IOError, but
# Python 3 just resumes the sleep.
def sleep(interval):
"""sleep that ignores EINTR in 2.x on Windows"""
while True:
try:
t = time.time()
time.sleep(interval)
except IOError as e:
if e.errno != errno.EINTR:
raise
interval -= time.time() - t
if interval <= 0:
break

View File

@ -3,6 +3,7 @@ import logging
import logging.config
import signal
from sys import platform
from typing import Any, AsyncGenerator, Callable, List, Optional, Tuple
try:
@ -192,6 +193,9 @@ class Service:
signal.signal(signal.SIGINT, global_signal_handler)
signal.signal(signal.SIGTERM, global_signal_handler)
if platform == "win32" or platform == "cygwin":
# pylint: disable=E1101
signal.signal(signal.SIGBREAK, global_signal_handler) # type: ignore
self._task = asyncio.create_task(_run())