Advice wanted: asynch I/O on unix

Russell E. Owen owen at astro.washington.edu
Mon Jul 23 12:57:36 EDT 2001


I have a unix C library that reads some parallel port cards 
(asynchronously), processes the data and writes it files. I want to be 
able to call it from Python and would love some advice. My unix 
experience is somewhat limited, as is my experience writing C modules 
for Python.

The present C program works as follows:
- open the parallel port as a file-like device (and config with ioctl)
- allocate some buffers
- call aioread to start reading into one buffer
- call aioread to queue a read into a 2nd buffer
- repeatedly poll the aioreads; when one finishes,
  processes the data, deallocate the buffer,
  and allocate a new buffer and queue an aioread on it
writing works similarly

It would be nicest to end up with as little C code as possible (i.e. 
move most of this functionality into Python). Some of the processing 
would be better done in Python, and it's so much easier to debug and 
modify things in Python.

I think I can rewrite most or all of this directly in Python, but surely 
I can do better than simply replicate this code? It looks awfully 
complex. Is there A Better Way? Ideally, I'd like to start a read into a 
big FIFO, then check every once in awhile and process the data that has 
arrived. In other words, somehow treat the parallel port card as a 
buffered stream. Is this practical, or should I just bite the bullet and 
code up all that fussy buffer manipulation?

(By the way, the device does come with a library that allows setting up 
a circular set of buffers. This would save some of the fussing with 
buffers, though I have my doubts about aspects of the interface and it 
means using a custom C library.)

Any advice would be appreciated.

-- Russell



More information about the Python-list mailing list