[Twisted-Python] client connecting to 2 servers (nonsimultaneously)

Jason Rennie jrennie at gmail.com
Wed Jan 12 18:15:17 MST 2011


Great explanation.  Thanks!

Jason

On Wed, Jan 12, 2011 at 4:40 PM, <exarkun at twistedmatrix.com> wrote:

> Some reactors have a different implementation of wakeUp than the above,
> but they all have the same goal.
>
> The reactor thread may be doing something which is going to block
> indefinitely (WaitForMultipleObjects, select(), epoll_wait(), etc).  The
> purpose of the wakeUp call is to cause that blocking call to end.  Once
> it ends, calls in the threadCallQueue can be processed.
>
> The reactor is written such that if you are running code in the same
> thread it is running in (ie, you are "in the reactor thread") then any
> event source you create (be it network or time or whatever), the reactor
> will be sure to service it in a timely manner.  For network event
> sources, this means it will include a descriptor in the select() (etc)
> call.  For timing event sources (ie callLater), it means the reactor
> will set a timeout on the select() (etc) call so that it returns before
> it is time for that delayed call to execute.
>
> However, if you are not in the reactor thread, then really the only
> thing you're allowed to do to Twisted is use reactor.callFromThread.
> Since this might happen at any time with respect to what the reactor
> thread is doing, there's no way to be sure a (let's call it a) thread
> call event will get handled in a timely fashion.  So this is the problem
> that wakeUp solves.  After the thread call event is added to
> threadCallQueue, wakeUp makes some event source the reactor is
> monitoring signal readiness (on POSIX, it writes a byte to a pipe the
> reactor is select()ing (etc) on; on Windows, it posts an event like you
> pasted above).  This ensures that if the reactor is asleep waiting for
> an event it will wake up soon, and then it will notice there are thread
> call events to process.
>
> Jean-Paul
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
Jason Rennie
Research Scientist, ITA Software
617-714-2645
http://www.itasoftware.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20110112/f402f27a/attachment.html>


More information about the Twisted-Python mailing list