Timeout a function in python
Posted on 2018-06-02 in Trucs et astuces • Tagged with Python
You can use signals and a context manager to acheive this. The idea is to register a function that will raise an exeption when the alarm signal is received and schedule the alarm signal for the timeout.
import signal from contextlib import contextmanager @contextmanager def timeout(time): # Register a function …
Continue reading