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

Steve Freitas sflist at ihonk.com
Mon Feb 12 03:11:06 EST 2007

On Sun, 2007-02-11 at 00:35 -0600, Eric Mangold wrote:
> 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.

Thanks for responding, Eric. After a couple of days I started to worry
about the quality of my question.

This is where I saw that note I mentioned above:


That's part of what I found a little confusing... If I understand them
correctly, these docs say the callable must be threadsafe, but if it is,
I should be able to call it willy nilly.


More information about the Twisted-Python mailing list