[Twisted-Python] deferToThread - supported alternative to the (deprecated) setTimeout method
Paul Moore
pf_moore at yahoo.co.uk
Tue May 23 14:49:23 MDT 2006
I have a program where I think that what I want to use is
deferToThread and setTimeout. However, the setTimeout method is marked
as deprecated - but I can't find a good supported alternative. Can
anyone help?
The situation I have is:
I need to do a large-ish number (50-100) of blocking calls in
parallel, and collect the results or any errors. In itself, this seems
like a suitable use for deferToThread (defer each call, and collect
the results in the deferred callback/errback).
The problem is that in rare cases, the blocking call can block
indefinitely. In this case, I need to make the call time out. However,
the underlying API offers no way to time out the call, so I have to do
this externally.
A quick prototype seems to work OK, using setTimeout to force a
timeout on the deferred, but it generates deprecation warnings for the
setTimeout call.
What should I be using to achieve this effect?
Thanks,
Paul.
--
I remember being impressed with Ada because you could write an infinite
loop without a faked up condition. The idea being that in Ada the
typical infinite loop would normally be terminated by detonation. --
Larry Wall
More information about the Twisted-Python
mailing list