Timeline for Timeout on a function call
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 17 at 18:08 | comment | added | Mark Storer | This isn't going to work in multiple threads because they'll stomp all over each other's timeouts. As this is an inherently multi-threaded problem.... ouch. No bueno. | |
| Jul 25, 2018 at 8:38 | comment | added | Petar Donchev | Upvote because it disables the alarm in finally. Without it this is a recipe for disaster. | |
| Nov 6, 2017 at 15:55 | comment | added | Trevor Boyd Smith | some gotchas i see... calling this from multi-threads would probably not work (which can be fixed by added a mutex)... however the greater issue is if the other code outside of this uses the SIGALRM handler then that code would get broken by this (because signals are a global resource i prefer to only modify signals in the top level python source code (i.e. preferably right after a process is started)). | |
| Aug 12, 2016 at 17:13 | comment | added | scottmrogowski | You should avoid setting kwargs to an empty dict. A common Python gotcha is that default arguments on functions are mutable. So that dictionary will be shared across all calls to timeout. It is much better to set the default to None and, on the first line of the function, add kwargs = kwargs or {}. Args is okay because tuples are not mutable. | |
| Nov 16, 2015 at 19:41 | comment | added | Chris Johnson | Max, not true - works on any POSIX-compliant unix. I think your comment should be more accurately, doesn't work on Windows. | |
| Mar 13, 2014 at 20:10 | comment | added | max | This is not the best solution because it only works on linux. | |
| Jun 12, 2013 at 20:23 | comment | added | Martin Konecny | One more note: The Unix signal method only works if you are applying it in the main thread. Applying it in a sub-thread throws an exception and will not work. | |
| Jun 11, 2013 at 15:21 | comment | added | Martin Konecny | You should also restore the original signal handler. See stackoverflow.com/questions/492519/… | |
| Dec 11, 2012 at 13:41 | history | answered | Alex | CC BY-SA 3.0 |