Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to timeout function in python, timeout less than a second
    text
    copied!<h3>Specification of the problem:</h3> <p>I'm searching through really great amount of lines of a log file and I'm distributing those lines to groups in order to regular expressions(RegExses) I have stored using the <code>re.match()</code> function. Unfortunately some of my RegExses are too complicated and Python sometimes gets himself to backtracking hell. Due to this I need to protect it with some kind of timeout. </p> <h3>Problems:</h3> <ul> <li><code>re.match</code>, I'm using, is Python's function and as I found out somewhere here on StackOverflow <em>(I'm really sorry, I can not find the link now :-( )</em>. It is very difficult to interrupt thread with running Python's library. For this reason threads are out of the game.</li> <li>Because evaluating of <code>re.match</code> function takes relatively short time and I want to analyse with this function great amount of lines, I need some timeout function that wont't take too long to execute <em>(this makes threads even less suitable, it takes really long time to initialise new thread)</em> and <strong>can be set to less than one second</strong>.<br> For those reasons, answers here - <a href="https://stackoverflow.com/questions/492519/timeout-on-a-python-function-call">Timeout on a function call</a> and here - <a href="https://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish">Timeout function if it takes too long to finish</a> with decorator (alarm - 1sec and more) are off the table. </li> </ul> <p>I've spent this morning searching for solution to this question but I did not find any satisfactory answer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload