python threads: newbie question

Aahz aahz at pythoncraft.com
Fri May 16 14:00:47 EDT 2003


In article <e9851925.0305080619.1b481c36 at posting.google.com>,
christoph <lehmann at puk.unibe.ch> wrote:
>
>for a experimental program, which should show a bmp every time I receive
>a TTL signal on the parallel port (happens, roughly every 1s), I want to
>log also any mouse responses (means, every time the mouse gets pressed,
>I log the exact time of the button-down event)...
>
>I think this is something to be done with threads? Do I understand this
>right: I have one thread, which polls the LPT  does the buffer-swapping
>for the stimulus presentation as soon as a TTL signal is received, and a
>second thread which polls the mouse...? 

The main problem with this is that you're running a real-time system of
sorts.  You'll probably want to handle the mouse event in a callback of
your GUI framework, but there's a possibility that you might lose the
TTL signal if it's short enough.  Most GUI frameworks don't work well
with multiple threads calling GUI methods, so you'll need to post an
event from the TTL thread to the GUI thread (using Queue.Queue), then do
the actual image update from the GUI thread.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles:  boring syntax, unsurprising semantics,
few automatic coercions, etc etc.  But that's one of the things I like
about it."  --Tim Peters on Python, 16 Sep 93




More information about the Python-list mailing list