[Twisted-Python] Using Twisted together with Windows Namespace Extensions

Hi everybody,
I try to implement an ActiveX component for a Windows Namespace Extension, such that the data of my server, a twisted perspective broker, can be accessed and browsed via the Windows explorer.
The challenge on writing something like this is, that once Windows asks my ActiveX component to open a folder, a file or any other object, Windows expects an immediate answer. But asking by twisted server just returns a deferred.
To emulate those synchronous calls, I could use the "deferredResult" methods from twisted.trials. But that way, I would not be able to handle parallel requests, e.g. from two or more explorers or other applications.
Does anybody know, how to emulate a synchronous call in twisted? Am I right, that using the deferredResult method causes problems with parallel requests?
I guess, the solution may be similar to the render method return server.NOT_DONE_YET solution used in web.resource and twisted.web.server.
thanks for any help on this,
Thorsten

On Mon, 2004-03-01 at 12:33, Thorsten Henninger wrote:
The challenge on writing something like this is, that once Windows asks my ActiveX component to open a folder, a file or any other object, Windows expects an immediate answer. But asking by twisted server just returns a deferred.
You probably want to run a thread (or more, depends what the APIs on the windows side expect) that runs in parallel to the Twisted thread, and blocks until Deferreds have results, and use it to handle these requests.

You probably want to run a thread (or more, depends what the APIs on the windows side expect) that runs in parallel to the Twisted thread, and blocks until Deferreds have results, and use it to handle these requests.
This works, thanks. When I started to write the code, I figured out various methods to start threads in twisted. Well, I do not really understand, how they differ. For example: reactor.runFromThread reactor.runInThread
and what is the difference between threads.deferToThread and reactor.callInThread ? Both methods worked fine.
Is it threadsafe to run the reactor in a thread?
regards,
Thorsten

On Tue, Mar 02, 2004 at 10:49:24AM +0100, Thorsten Henninger wrote: [...]
Well, I do not really understand, how they differ. For example: reactor.runFromThread reactor.runInThread
and what is the difference between threads.deferToThread and reactor.callInThread ? Both methods worked fine.
Have you seen these links?
http://twistedmatrix.com/documents/current/howto/threading http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... http://twistedmatrix.com/documents/current/api/twisted.internet.threads.html...
Note that deferToThread is just a simple (but useful!) wrapper around callInThread -- you can read the implementation in twisted/internet/threads.py, it's quite short.
Let us know if it still doesn't make sense. Those docstrings are a little confusing.
Is it threadsafe to run the reactor in a thread?
The reactor doesn't care which thread it is run in (although if it's not Python's main thread you might want to set installSignalHandlers=0).
-Andrew.
participants (3)
-
Andrew Bennetts
-
Itamar Shtull-Trauring
-
Thorsten Henninger