mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-08 04:08:11 +08:00
Refactor timeout handling to handle AttributeError and ValueError for Windows users (#234)
This commit is contained in:
+9
-4
@@ -22,11 +22,13 @@ class TimeoutHandler:
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
signal.signal(signal.SIGALRM, self.raise_timeout_exception)
|
signal.signal(signal.SIGALRM, self.raise_timeout_exception)
|
||||||
except AttributeError: # AttributeError is raised for Windows users
|
signal.alarm(self._timeout)
|
||||||
|
except (
|
||||||
|
ValueError,
|
||||||
|
AttributeError,
|
||||||
|
): # AttributeError or ValueError might be raised for Windows users
|
||||||
logger.debug(_("SIGALARM is not available on your platform"))
|
logger.debug(_("SIGALARM is not available on your platform"))
|
||||||
|
|
||||||
signal.alarm(self._timeout)
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
if self._timeout == -1:
|
if self._timeout == -1:
|
||||||
return
|
return
|
||||||
@@ -34,5 +36,8 @@ class TimeoutHandler:
|
|||||||
try:
|
try:
|
||||||
signal.alarm(0)
|
signal.alarm(0)
|
||||||
signal.signal(signal.SIGALRM, signal.SIG_DFL)
|
signal.signal(signal.SIGALRM, signal.SIG_DFL)
|
||||||
except AttributeError: # AttributeError is raised for Windows users
|
except (
|
||||||
|
ValueError,
|
||||||
|
AttributeError,
|
||||||
|
): # AttributeError or ValueError might be raised for Windows users
|
||||||
logger.debug(_("SIGALARM is not available on your platform"))
|
logger.debug(_("SIGALARM is not available on your platform"))
|
||||||
|
|||||||
Reference in New Issue
Block a user