I'm trying to build a python timeout exception that runs in milliseconds.
The python signal.alarm function has a 1 second resolution.
How would one get an equivalent function that requests a SIGALRM signal to a given process in, say milliseconds, as opposed to seconds?
I've found no simple solutions as of yet.
Thanks in advance for your input.
The alarm() function is used to generate a SIGALRM signal after a specified amount of time elapsed.
SIGALRM is an asynchronous signal. The SIGALRM signal is raised when a time interval specified in a call to the alarm or alarmd function expires. Because SIGALRM is an asynchronous signal, the SAS/C library discovers the signal only when you call a function, when a function returns, or when you issue a call to sigchk .
Since the kernel already keeps per-process data structures ( task_struct ), it just stores the desired alarm time in there. Then Linux just uses its internal timer system to register a callback at the specified time. Said callback then delivers the SIGALRM to your process.
Use signal.setitimer() instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With