fix: only call signal if executing on the main thread (#10677)

This commit is contained in:
henryyeh 2020-08-25 16:57:58 -07:00 committed by GitHub
parent 502f4db6f9
commit a6101f72c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ import re
import signal
import smtplib
import tempfile
import threading
import traceback
import uuid
import zlib
@ -631,8 +632,9 @@ class timeout: # pylint: disable=invalid-name
def __enter__(self) -> None:
try:
signal.signal(signal.SIGALRM, self.handle_timeout)
signal.alarm(self.seconds)
if threading.current_thread() == threading.main_thread():
signal.signal(signal.SIGALRM, self.handle_timeout)
signal.alarm(self.seconds)
except ValueError as ex:
logger.warning("timeout can't be used in the current context")
logger.exception(ex)