[Twisted-Python] Calling into Twisted from a Windows service control
teratorn at twistedmatrix.com
Mon Feb 12 10:14:53 EST 2007
On Mon, 12 Feb 2007 02:11:06 -0600, Steve Freitas <sflist at ihonk.com> wrote:
> 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>
>> > Hi,
>> > Itamar posted earlier in this list how to run Twisted as a service:
>> > 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
>> > though, so from looking at the howtos, it looks like the right thing
>> > 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
>> > 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:
>> 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
>> 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.
Wow, that doc string is quite misleading. Good catch :)
Please file a bug and assign to itamar since he has his name in that file
It's true that since you're writing a multi-threaded app the callable
*may* need to be thread-safe. But in so far as callFromThread is concerned
it doesn't need to be.
More information about the Twisted-Python