New Select Module



There is now select support in the [ jython distribution], as of version 2.2rc1.

The new module presents an API which is as close as possible to the [ cpython select module], Jython supports both the

  1. function
  2. [ select.poll objects].

When using the select module, you should be guided by the cpython documentation: any deviation from the behaviour described in that documentation should be considered a bug and [ reported] as such.

Differences between cpython and jython

However, due to fundamental differences in the behaviour of java and C on various platforms, there are differences between the cpython and jython select modules which are not possible to code around. Those differences will be listed here.

Only sockets in non-blocking mode can be multiplexed

On cpython, when a socket is passed to or select.poll, it can either be in blocking or non-blocking mode.

However, [,%20int) java will only permit multiplex operations on sockets that are in non-blocking mode]; any attempt to pass a socket in blocking mode to either or select.poll().register will fail with an exception.

To summarise

  1. You must set a socket in non-blocking mode before passing it to the select function or registering it with a poll object
  2. Any attempt to register a blocking socket for multiplex will raise a select.error exception, with an error code of errno.ESOCKISBLOCKING
  3. If a socket is currently registered with a select.poll object, an attempt to change it to blocking mode will give rise to the same exception.
  4. A socket can only be placed in blocking mode if it is not registered with a select.poll object.