[Twisted-Python] Asynchronicity

Jean-Paul Calderone exarkun at divmod.com
Sat Jun 9 16:07:13 EDT 2007


On Sat, 09 Jun 2007 20:51:39 +0100, Simon Pickles <sipickles at hotmail.com> wrote:
>Integrating into a GUI is just one example. In my case, I am using
>Tkinter on win32. The GUI will be switched off when the server is
>running, its simply a debug controller...

There's Tkinter support. ;)

>
>I'm more interested in how a twisted server manages to perform any other
>logic. For a game server, a fair amount of time needs to be devoted to
>object and memory management, AI, database access etc

Sure (though I'm going to disregard "object and memory management" ;).  If
you have code for an NPC in the game, there are two possibilities for when
it runs:

It might run in response to events in the game world (possibly timing
events).  In this case, you simply implement the appropriate event handlers
and it will have a chance to run at the appropriate times.

It might need to run "as much as possible" - for example, to incrementally
refine some behavior, to the limit imposed by available system resources.
In this case, you might want to use a separate process and do IPC, or a
thread might be appropriate, or you could implement something based on
cooperative threading (for example, by implementing the logic as an iterator
and using twisted.internet.task.Cooperator to run it as frequently as there
is CPU time to do so).

> [snip]
>
>I thought twisted.interface.reactor.iterate() might be my answer. API
>docs say about iterate:

iterate is most likely a dead end, I wouldn't spend much time there.

Jean-Paul




More information about the Twisted-Python mailing list