[Tutor] Listen for input while performing other tasks

Sean Carolan scarolan at gmail.com
Sun Nov 25 12:06:54 CET 2012


I'm working on a python script that runs on a Raspberry Pi.  The script
detects when hardware buttons are pressed, and then runs functions based on
that input.

I want to be able to always listen for a button press, no matter what the
script is doing at the current moment.  When a button press is detected,
the script should stop whatever it is doing, and move to the next "mode" or
function.

So far I've only been able to come up with kludgy implementations with lots
of short time.sleep() calls alternating with checks to see whether the
buttons were pressed or not.

There has to be a cleaner way to do this.  Do you have any ideas how to
make this work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121125/d1e39fa0/attachment.html>


More information about the Tutor mailing list