[Twisted-Python] Calling into Twisted from a Windows service control

Eric Mangold teratorn at twistedmatrix.com
Sun Feb 11 01:35:41 EST 2007


On Thu, 08 Feb 2007 12:35:03 -0600, Steve Freitas <sflist at ihonk.com> wrote:

> Hi,
>
> Itamar posted earlier in this list how to run Twisted as a service:
>
> http://twistedmatrix.com/pipermail/twisted-python/2003-October/006081.html
>
> Now, I want to trap some Windows events and make some calls into my
> Twisted app (calling disconnect() on a pb.PBClientFactory instance is
> one example). I'll be setting up the trapping in the service code above,
> though, so from looking at the howtos, it looks like the right thing for
> me to do when I get some event is:
>
> reactor.callFromThread(factory.disconnect)
>
> The docs state, though, that the callable must be thread safe. Does that
> mean I need to use threadable.synchronize() to put a lock around
> factory.disconnect? Or whatever else I'm calling into?
>
> Steve

I guess these are the docs you're refering to:

http://twistedmatrix.com/projects/core/documentation/howto/threading.html

Actually, they don't say that the callable must be thread-safe. Indeed,  
the only reason you need to use callFromThread is if the callable *is not*  
thread-safe. What callFromThread does is schedule the call to take place  
within the main thread at the convenience of the reactor.

Hope that helps,
-- 
Eric Mangold
Twisted/Win32 Co-Maintainer




More information about the Twisted-Python mailing list