I got a kivy app with a main GUI thread and RFID thread (a daemon thread which reads from a device and puts jobs to a Queue()
). There is schedule interval set by the clock that queries the Queue() for any incoming job. GUI has an image in the background, whenever a job is found in the Queue, all widgets are cleared, an image is added to the to the widgets then it is cleared after two seconds, and the loop goes on.
class MainScreen(Screen):
background = BACKGROUND
def __init__(self):
super(MainScreen, self).__init__()
# Checking for cart input 30 times per second
self.event = Clock.schedule_interval(self.listen_for_cart_input, EVENT_INTERVAL_RATE)
self.add_widget(Image(source=self.background))
def listen_for_cart_input(self, dt):
try:
code = carts.get(timeout=QUEUE_TIMEOUT)
Clock.unschedule(self.event)
# Do Something
self.handle_transition()
except (Empty, AssertionError):
pass
def handle_transition(self):
trigger_back_to_main = Clock.create_trigger(self.back_to_main, timeout=TRANSITION_TIMEOUT)
self.clear_widgets()
self.add_widget(Image(source=image))
trigger_back_to_main()
def back_to_main(self, dt):
self.clear_widgets()
self.add_widget(Image(source=self.background))
self.event = Clock.schedule_interval(self.listen_for_cart_input, EVENT_INTERVAL_RATE)
It works perfectly but few times a day (the card insertion happens ~100 times per day) after inserting a card, the screen goes blank raising the following exception. Note that only screen goes blank and the app is functioning properly. Also after inserting card multiple times, the screen comes back again showing the image.
is it a bug? I can't figure out the cause of the raised execption
[WARNING ] stderr: Exception in thread Thread-3:
[WARNING ] stderr: File "/usr/local/lib/python3.5/threading.py", line 914, in _bootstrap_inner
[WARNING ] stderr: self.run()
[WARNING ] stderr: File "/usr/local/lib/python3.5/threading.py", line 862, in run
[WARNING ] stderr: self._target(*self._args, **self._kwargs)
[WARNING ] stderr: File "/usr/local/lib/python3.5/site-packages/kivy/input/providers/hidinput.py", line 687, in _thread_run
[WARNING ] stderr: data = fd.read(struct_input_event_sz)
[WARNING ] stderr: OSError: [Errno 19] No such device
The problem was related to the HDMI cable that connected the raspberry pi to the lcd. I fixed it by changing the cable.