BPettersen at NAREX.com
Tue Oct 15 02:20:36 CEST 2002
> From: Aahz [mailto:aahz at pythoncraft.com]
> In article <cb035744.0210140629.43767d40 at posting.google.com>,
> Will Stuyvesant <hwlgw at hotmail.com> wrote:
> >I am trying to come up with a method to run a function in such a way
> >that the whole thing will take at most x milliseconds, with x a
> >reasonable value like 200. If the function is not finished by that
> >time, a default value should be used. If the function *does* finish
> >time, the return value of the function should be used.
> That last part isn't really possible, not if there are
> statements that depend on external connectivity like I/O.
> But it's certainly possible to make your main loop work the
> way you want: have your function put its result on a
> Queue.Queue. In your main function, time.sleep() for however
> long it's supposed to, then do a non-blocking get() on the
> queue. If the get() fails, do whatever's appropriate. This
> gets trickier if your main program needs to be responsive
> during the 200ms, but it's not impossible.
You should be able to re-work the "Futures" receipe
doing what you want... (basically set a timestamp in __init__ and
conditionally return a default value in __call__).
More information about the Python-list