selectmodule on PS3

As part of a game that we are developing on the Sony PS3, we are porting Stackless Python 2.7 to run on it.  What would be more natural?

Python is to do what it does best, act as a supervising puppetmaster, running high-level logic that you don’t want to code using something primitive such as C++.

While there are many issues that we have come across and addressed (most are minor), I’m just going to mention a particular issue with sockets.

An important role of Python will be to manage network connection using sockets.  We are using the Stacklesssocket module with Stackless Python do do this.  For this to work, we need not only the socketmodule but also the selectmodule.

The PS3 networking api is mostly BSD compliant with a few quirks.  Porting these modules to use it is mostly a straightforward affair of providing #defines for some API calls that have different names, dealing with APIs that are missing (return NotImplementedError and such) and mapping error values to something sensible.  For the most part, it behaves exactly as you would expect.

We ran into one error though, prompting me to write special handling code for select() and poll().  the Sony implementation of these functions not only returns with an error if they themselves fail (which would be serious) but they also indicate a error return if a socket error is pending on one of the sockets.  For example, if a socket receives a ECONNRESET, while you are waiting for data to arrive, select() will return with an ECONNRESET error indicator.  Not what you would expect.

The workaround is to simply filter the error values from select() and poll() and ignore the unexpected socket errors.  Rather, such a return must be considered a successful select()/poll() and for the latter function, ‘n’, the number of valid file descriptors, having been set as -1, must be recreated by walking the list of file descriptors.


4 thoughts on “selectmodule on PS3

  1. Very interesting stuff! I know its early days but would these patches for the PS3 be released upstream or would this be bound under a development agreement with Sony?

    Still, hearing Python is being ported to PS3 is excellent news alone, closed or not.

  2. Well, changes aren’t that great. The api is very posix-like but there are significant omissions. One would have to expand a lot on the HAVE_FOOFUNC #ifdefs to do it cleanly. In fact, it would sometimes be simpler to have HAVENT_FOOFUNC ifdefs which can be defined by the minority of platforms that don’t support a feature.

    On the other hand, it is likely to be of a very limited interest. The target is the Sony PS3 SDK with the SN compilers, and these are available only to licensed PS3 developers. I know of only one other company interested in using Python on that platform.

    Given this, It’s very unlikely that anyone would be interested in accepting PS3 specific build features into the core, since it wouldn’t even be possible to provide buildbots!

    However, making the changes available to other Sony developers, I don’t know if that would be permissable according to our contract. Note that I even consulted another non-lawyer before posting the details about the socketselect() call and decided that it was probably ok!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s