Diez B. Roggisch wrote: > Nick Craig-Wood wrote: > > >>Did anyone write a contextmanager implementing a timeout for >>python2.5? >> >>And have it work reliably and in a cross platform way! > > Cross platform isn't the issue here - reliability though is. To put it > simple: can't be done that way. You could of course add a timer to the > python bytecode core, that would "jump back" to a stored savepoint or > something like that.
Early versions of Scheme had a neat solution to this problem. You could run a function with a limited amount of "fuel". When the "fuel" ran out, the call returned with a closure. You could run the closure again and pick up from where the function had been interrupted, or just discard the closure. So there's conceptually a clean way to do this. It's probably not worth having in Python, but there is an approach that will work. LISP-type systems tend to be more suitable for this sort of thing. Traditionally, LISP had the concept of a "break", where execution could stop and the programmer (never the end user) could interact with the computation in progress. John Nagle -- http://mail.python.org/mailman/listinfo/python-list