James Stroud <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Did anyone write a contextmanager implementing a timeout for > > python2.5? > > > > I'd love to be able to write something like > > > > with timeout(5.0) as exceeded: > > some_long_running_stuff() > > if exceeded: > > print "Oops - took too long!" > > > > And have it work reliably and in a cross platform way! > > > > From my experiments with timeouts I suspect it won't be possible to > > implement it perfectly in python 2.5 - maybe we could add some extra > > core infrastructure to Python 3k to make it possible? > > > > I'm guessing your question is far over my head, but if I understand it, > I'll take a stab: > > First, did you want the timeout to kill the long running stuff?
Yes. > I'm not sure if its exactly what you are looking for, but I wrote a > timer class that does something like you describe: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464959 > > Probably you can do whatever you want upon timeout by passing the > appropriate function as the "expire" argument. I don't think your code implements quite what I meant! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list