16 lines
296 B
Python
16 lines
296 B
Python
import signal
|
|
import time
|
|
|
|
def handler(signo, frame):
|
|
raise RuntimeError("Timeout")
|
|
|
|
signal.signal(signal.SIGALRM, handler)
|
|
|
|
while True:
|
|
try:
|
|
signal.alarm(5) # seconds
|
|
time.sleep(10)
|
|
print("Working...")
|
|
except Exception as e :
|
|
print(e)
|
|
continue |