I understand that when you say โusing while the truthโ, you mean a survey that checks the state of gpio at a certain time interval to detect changes, due to some processing time.
One option to avoid polling (from docs ) is wait_for_edge ():
The wait_for_edge () function is designed to block the execution of your program until an edge is detected.
It seems that you are looking for; the program will be suspended execution using epool () IIUC.
Now suppose you meant that you did not want to use GPIO.wait_for_edge () because you did not want to lose GPIO state changes during event processing, you would need to use threads. One possible solution is Queue events and customization:
- One thread for
while True: queue.put(GPIO.wait_for_edge(...)) . - Another thread to execute
Queue.get() .
source share