Reading asynchronous data from a serial device

ge at nowhere.none.bbs ge at nowhere.none.bbs
Mon Jul 17 15:10:05 EDT 2000


In article <1zIc5.1394$6E.263441 at ptah.visi.com>, Eric Hopper wrote:
>In article <8kuvg0$kg2$1 at nnrp1.deja.com>, julesk24 at my-deja.com wrote:
>>
>> 1) Is there any (easy) way for me to cause the thread to exit
>> (not just join the processes) after a timeout on a read?
>
>I believe you can start the thread as a daemon thread and not
>have the join problem.  When the thread exits, it just
>disappears and doesn't wait for its parent thread to notice.
>
>I'm not sure how to start it as a daemon thread.
>
>> 2) Is there a better way of reading for data (without starting
>> my own thread for the read process and then trying to exit out
>> of the thread after a period of time)?
>
>Yes.  Use a select(2), or poll(2) based mechanism.  I believe
>the asyncore module handles this for you.  I will also be
>adding a python wrapper to my C++ StreamModule
>(http://www.sourceforge.net/projects/strmod) system someday,
>and that should also nicely handle the problem.

You can use select/poll as Eric suggested (with appropriate
timeout) or you can configure the serial driver itself to
timeout by setting VMIN and VTIME appropriately. If you want to
do this, take a look at the Linux Serial-Programming-HOWTO.
IIRC, all of the termio stuff maps pretty much directly into
Python.

I'd start with select/poll and its timout.

--
Grant Edwards                   grante             Yow!  I'm DESPONDENT... I
                                  at               hope there's something
                               visi.com            DEEP-FRIED under this
                                                   miniature DOMED STADIUM...



More information about the Python-list mailing list