@@ -86,8 +86,15 @@ def handler(signum, frame):
8686 raise TimeoutError
8787
8888 try :
89- create_signal (SIGALRM , handler )
90- setitimer (ITIMER_REAL , timeout )
89+ # We try to setup the signal. If we are not in the main thread
90+ # this will raise a ValueError. In this case we just run the
91+ # function without timeout.
92+ try :
93+ create_signal (SIGALRM , handler )
94+ setitimer (ITIMER_REAL , timeout )
95+ except ValueError :
96+ pass
97+
9198 return NO_ERROR , func (* (args or ()), ** (kwargs or {}))
9299
93100 except TimeoutError :
@@ -97,7 +104,10 @@ def handler(signum, frame):
97104 return ERROR_MSG + traceback_format_exc (), NO_VALUE
98105
99106 finally :
100- setitimer (ITIMER_REAL , 0 )
107+ try :
108+ setitimer (ITIMER_REAL , 0 )
109+ except ValueError :
110+ pass
101111
102112elif on_windows :
103113 """
@@ -191,4 +201,4 @@ def fake_interruptible(func, args=None, kwargs=None, timeout=DEFAULT_TIMEOUT):
191201 try :
192202 return NO_ERROR , func (* (args or ()), ** (kwargs or {}))
193203 except Exception :
194- return ERROR_MSG + traceback_format_exc (), NO_VALUE
204+ return ERROR_MSG + traceback_format_exc (), NO_VALUE
0 commit comments