Twisted and Pygame

Posted by
April 24th, 2010 4:35 pm

Twisted provides a network reactor framework for Python that simplifies network programming down to implementing methods on a class that inherits from one of their base classes. You can have an arbitrary number of classes and instances of those classes managing the chatter with a particular connection.

My current problem with it is that it doesn’t seem to provide an API for adding more sources of events to be handled. Pygame is equally uncooperative in this regard. I can’t, for instance, tell a Twisted reactor to listen to another arbitrary file descriptor and how to handle it. Glib has “GSources” which encapsulate this notion, and are abstracted well enough for applications which have to poll for data readiness that is unrelated to a file descriptor. Rarely in a *NIX environment will you ever have such a thing, but platforms like MSWindows have a whole slew of data sources which you can’t select() on. (That may be out of date. It’s been a long time since I’ve done MSWindows API.)

The compromise I’ll have to make for LD17 is to use a timer-driven callback which pumps my Pygame event loop. The Twisted API for this is the callLater() reactor method which accepts a timeout and a callback function as arguments.

Anyone know anything better?


2 Responses to “Twisted and Pygame”

  1. ickylevel says:

    Twisted is cool but wtf ? Multiplayer ? Are you insane ?

  2. hdon says:

    It can be done!

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]