python-list query re sockets, select or: twisted and other file-descriptors & twisted question

John Benson jsbenson at bensonsystems.com
Sat Nov 29 23:26:50 EST 2003


In response to the question about doing serial i/o and using a select
statement, I'd like to quote from
http://www.python.org/doc/current/lib/module-select.html

select(iwtd, owtd, ewtd[, timeout])

This is a straightforward interface to the Unix select() system call. The
first three arguments are lists of `waitable objects': either integers
representing file descriptors or objects with a parameterless method named
fileno() returning such an integer. The three lists of waitable objects are
for input, output and `exceptional conditions', respectively. Empty lists
are allowed, but acceptance of three empty lists is platform-dependent. (It
is known to work on Unix but not on Windows.) The optional timeout argument
specifies a time-out as a floating point number in seconds. When the timeout
argument is omitted the function blocks until at least one file descriptor
is ready. A time-out value of zero specifies a poll and never blocks.
The return value is a triple of lists of objects that are ready: subsets of
the first three arguments. When the time-out is reached without a file
descriptor becoming ready, three empty lists are returned.
Among the acceptable object types in the lists are Python file objects (e.g.
sys.stdin, or objects returned by open() or os.popen()), socket objects
returned by socket.socket().  You may also define a wrapper class yourself,
as long as it has an appropriate fileno() method (that really returns a file
descriptor, not just a random integer). Note: File objects on Windows are
not acceptable, but sockets are.  On Windows, the underlying select()
function is provided by the WinSock library, and does not handle file
desciptors that don't originate from WinSock.

(end quote)

So, select might not yet work on Windows serial ports as well as sockets.
This is also a subject of interest to me, but all I can think of is handling
the sockets via select() and polling periodically for data on the serial
port using callLater() and some win32 calls. Maybe the win32 serial port
handling could even be wrapped in a 'waitable object' as described above for
use with the Python select() call.

I recall reading somewhere that the twisted framework has the ability to
handle serial communications in connection with Global Positioning System
device interaction, but don't have any information about it. I'm going to
post this to the twisted mailing list :

Question for twisted folks: How can I add serial Windows serial port
communications as a twisted protocol? Please cross-post back to the
python-list.







More information about the Python-list mailing list