{"author_name":"hdon","cat":"LD #17 - Islands - 2010","comments":[{"author_name":"ickylevel","time":"April 24, 2010 4:36 pm","epoch":1272144960,"text":"Twisted is cool but wtf ? Multiplayer ? Are you insane ?","spam":"N"},{"author_name":"hdon","time":"April 25, 2010 10:37 am","epoch":1272209820,"text":"It can be done!","spam":"N"}],"epoch":1272144900,"likes":0,"metadata":{"p_key":"71011","p_author":"hdon","p_authorkey":"1900","p_urlkey":"106832","p_title":"Twisted and Pygame","p_cat":"LD #17 - Islands - 2010","p_event":"LD17","p_time":"1272144900","p_likes":"0","p_comments":"2","p_status":"UPD5","us_key":"1900","us_name":"hdon","us_username":"hdon","event_start":"1271980800","event_key":"3","event_name":"LD17"},"text":"<p>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.<\/p>\n <p>My current problem with it is that it doesn&#8217;t seem to provide an API for adding more sources of events to be handled. Pygame is equally uncooperative in this regard. I can&#8217;t, for instance, tell a Twisted reactor to listen to another arbitrary file descriptor and how to handle it. Glib has &#8220;GSources&#8221; 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&#8217;t select() on. (That may be out of date. It&#8217;s been a long time since I&#8217;ve done MSWindows API.)<\/p>\n <p>The compromise I&#8217;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.<\/p>\n <p>Anyone know anything better?<\/p>","time":"April 24th, 2010 4:35 pm","title":"Twisted and Pygame"}