[Twisted-Python] Breaking up long computations

Nicola Larosa nico at tekNico.net
Wed Aug 6 06:18:42 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> - check that there are no more scheduled events that need to be run *in
>   this iteration*.  It *won't* pull anything off the delayed call queue
>   that wasn't there before it started processing delayed calls.  Let's
>   assume there's nothing else to do here.  [I'm guessing this is the bit
>   you weren't getting, but I'll tell complete story anyway, just in case]
> - then the reactor will finish that iteration, so it'll start a new one.
> - it'll peek at the first thing on the delayed call queue, to see how
>   long until something needs to be called
> - it will then check for IO events using select (or poll, or kqueue, or
>   ...).  It passes the time to the next event as the timeout for the
>   select call, so if there's been no unprocessed network activity since
>   the last   iteration, it will block until that timeout, or there is
>   some activity (which ever happens first).
> - If there's any IO events to be processed, it calls the relevant event
>   handlers.  In my example above, perhaps a message from a client just
>   arrived, this will lead (via a few layers of abstraction) to a
>   protocol's dataReceived method being called (which in turn may call a
>   'messageReceived' handler and spawn a database query, or something).
> - After the IO events have been processed, it will finally turn its
>   attention back to the delayed call queue, find all of them that are now
>   due, and run those.
> - And then the next reactor iteration will happen.

So, the reactor goes back and forth between the select and the call queue at
each iteration, that's what I was overlooking.


> I hope I've made things clearer, rather than just confusing them :)

Yes, you've been most helpful, thanks.


- --
"Unlike some other scripting languages, Python syntax tends to be in
words rather than typographical syntax - it's very unlikely you'll be
writing lines of code that look like comic book curse words. As a result,
when you have to come back to your code six months later, odds are you
will still be able to understand it."  Samuele Pedroni and Noel Rappin

Nicola Larosa - nico at tekNico.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/MNYAXv0hgDImBm4RAp10AJ0R+FFqkh5Oeb314OX24FZvaIPYQgCfV97q
IyHhf9ugv8o/SdBZqdJUxpw=
=bUvg
-----END PGP SIGNATURE-----






More information about the Twisted-Python mailing list