I know the "signal" module in python 2.7, in general, we can use the following code to timeout a main-thread function call:
import signal
def signal_handle_timeout:
raise Exception("Timeout!")
signal.signal(signal.SIGALRM, signal_handle_timeout)
signal.alarm(seconds)
try:
long_time_function()
except Exception as ex:
print ex
But it only can run in main-thread, if try to run in sub-thread, it throw this error: 'ValueError: signal only works in main thread'
In Python, how can we timeout a function call in sub-thread?