[Twisted-Python] Suspending a result

Uwe C. Schroeder uwe at oss4u.com
Sat Sep 13 11:27:57 MDT 2003


Hi,

maybe I'm sitting on my brains here, but anyways:
I have a (possibly) blocking function. The core work of it is handled in a 
separate thread, so the blocking is not a problem for Twisted.
However - I need to get rid of the deferred callbacks. So basically what I'm 
trying to do is to have a class/method that wraps the blocking code WITHOUT 
returning a deferred. Instead I'd like to "suspend" the return, certainly 
without blocking twisted. So here is some "pseudocode" to clarify what I want 
to do:

# the blocking function itself
def possibly_blocking(params):
	do something blocking

Normally I would call this by
	result=possibly_blocking("Blah")

which may or may not block due to what's inside the function.
In 99% of the time it will return a result quite quickly, so no blocking.
BUT what if. So I want to make the
result=xxx
call "wait" for the result, without a deferred coming back. So I'd have to 
wrap that up somehow, so that the call seems to be waiting, but in what is 
called returning the result is delayed. 
I think one might be able to accomplish this with some kind of class that 
wraps the call and checks for the resultset once in a while, and when the 
result is there it returns the result.

It's pretty similar to the way GUI's handle modal dialogs. The original modal 
dialog call will never return, until the dialog is closed, however the rest 
of the gui doesn't block, since internally scheduling still goes on.
So can one wrap a "call / deferred / result" chain and block the caller, 
without blocking twisted completely ?

Any help would be appreciated.
(BTW: I don't want to use deferreds as the original resultset, since that 
would mean having to write tremendous state machines just to retain the order 
of the results depending on each other)

	UC

--
Open Source Solutions 4U, LLC	2570 Fleetwood Drive
Phone:  +1 650 872 2425		San Bruno, CA 94066
Cell:   +1 650 302 2405		United States
Fax:    +1 650 872 2417





More information about the Twisted-Python mailing list