federico3 / trovastelle

An arrow that points at interesting objects in the sky, inspired by the art installation at the JPL mall.
2 stars 0 forks source link

Add a try-catch for display update #60

Open federico3 opened 7 months ago

federico3 commented 7 months ago

App keeps crashing while updating the display due to a finicky i2c bus. Ok, it's an hardware issue, but it's annoying.

Jan 28 11:40:14 trovastelle2 systemd[1]: Started Trovastelle service.
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]: Slow display update prop is False
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]: Traceback (most recent call last):
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/trovastelle/src/celestial_compass/trovastelle.py", line 451, in <module>
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     asyncio.run(ts.run(),debug=_debug)
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     return loop.run_until_complete(main)
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     return future.result()
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/trovastelle/src/celestial_compass/trovastelle.py", line 412, in run
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     await cc_task
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/trovastelle/src/celestial_compass/compass.py", line 174, in run
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     await main_task
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/trovastelle/src/celestial_compass/compass.py", line 239, in _run_main
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self.display_controller.display_observable_data(
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/trovastelle/src/celestial_compass/display_manager.py", line 269, in display_o>
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self._display_text_in_box(
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/luma/core/render.py", line 43, in __exit__
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self.device.display(self.image)
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/luma/oled/device/__init__.py", line 225, i>
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self.data(list(buf))
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/luma/core/device.py", line 55, in data
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self._serial_interface.data(data)
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/luma/core/interface/serial.py", line 125, >
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     write(list(data[i:i + block_size]))
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/luma/core/interface/serial.py", line 134, >
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     self._bus.i2c_rdwr(self._i2c_msg_write(self._addr, [self._data_mode] + data))
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:   File "/home/pi/.local/lib/python3.9/site-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]:     ioctl(self.fd, I2C_RDWR, ioctl_data)
Jan 28 11:43:54 trovastelle2 trovastelle.sh[4122]: OSError: [Errno 121] Remote I/O error
federico3 commented 7 months ago

Actually we have already done that but OSError is not caught...

federico3 commented 7 months ago

https://www.geeksforgeeks.org/handling-oserror-exception-in-python/

https://stackoverflow.com/questions/63444603/catch-a-specific-oserror-exception-in-python-3

https://docs.python.org/3/library/exceptions.html#os-exceptions