Twisted: 1 thread in the reactor pattern

jacopo jacopo.pecci at gmail.com
Fri Sep 25 07:25:23 CEST 2009


On Sep 24, 7:54 pm, exar... at twistedmatrix.com wrote:
> On 07:10 am, jacopo.pe... at gmail.com wrote:
>
>
>
>
>
> >On Sep 23, 5:57 pm, exar... at twistedmatrix.com wrote:
> >[snip]
>
> >>It isn't possible.  While the remote methods are running, other events
> >>are not being serviced.  This is what is meant when people describe
> >>Twisted as a "*cooperative* multitasking" system.  Event handlers
> >>(such
> >>as remote methods) run for a short enough period of time that it
> >>doesn't
> >>matter that the reactor is prevented from accepting new connections
> >>(or
> >>what have you) for the duration of their execution.
>
> >>Jean-Paul
>
> >Jean -Paul, not sure I have understood.
> >Say I have one server S and two clients C1 and C2 (all on separate
> >machines).
>
> >(a)     C1 requests a remote call of f1() to S, f1() requires 5 minutes
> >of
> >processing.
> >(b)     S  puts f1() in a queue and returns immediately a Deferred to
> >C1.
> >(c)     Now f1() starts and keeps S 19s processor busy for 5 mins
> >(d)      after few seconds C2 requests a remote call f2() to S.
> >(e)     On S the processor is already engaged with f1() but still
> > 1Csomeone 1D on S is able to accept the request from C2, put it in a
> >queue (after f1()) and return a Deferred to C2.
> >(f)     At some point after f1() is finished f2() will start
>
> >I believe (b) is what you say  1Crun for a short enough period of time
> >that it doesn't
> >matter that the reactor is prevented from accepting new connections
> >(or
> >what have you) for the duration of their execution. 1D ?!
>
> If you have a function that takes 5 minutes to run, then you're blocking
> the reactor thread for 5 minutes and no other events are serviced until
> the function finishes running.
>
> You have to avoid blocking the reactor thread if you want other events
> to continue to be serviced.  There are various strategies for avoiding
> blocking.  Different strategies are appropriate for different kinds of
> blocking code.
>
> Jean-Paul- Hide quoted text -
>
> - Show quoted text -

Even if the server is engaged in a 5 minutes processing other arriving
requests of callRemote() are queued and  Deferreds are returned
immediately. So the reactor is responding somehow.
Isn’t it?!
On the Server I am using: reactor.listenTCP(port,  pb.PBServerFactory
(MyClass()))

Could you suggest me any doc to better understand?

Thanks, Jacopo



More information about the Python-list mailing list