generated from pimoroni/boilerplate-python
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
When a device handle can't be created (likely due to the io already being in use), the last traceback implies "not found". I've seen this confuse people.
Eg:
Traceback (most recent call last):
File "/home/pi/robot/tests/test_motors.py", line 5, in <module>
board = inventorhatmini.InventorHATMini()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/robotvenv/lib/python3.11/site-packages/inventorhatmini/__init__.py", line 106, in __init__
self._pin_user_sw = gpiodevice.get_pin(self.PI_USER_SW_PIN, "IHM-SW", INPD)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/robotvenv/lib/python3.11/site-packages/gpiodevice/__init__.py", line 163, in get_pin
lines = chip.request_lines(consumer=f"{consumer}-{label}", config={line_offset: settings})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/robotvenv/lib/python3.11/site-packages/gpiod/chip.py", line 331, in request_lines
req_internal = cast(_ext.Chip, self._chip).request_lines(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 16] Device or resource busy
Exception ignored in: <function InventorHATMini.__del__ at 0xf7008118>
Traceback (most recent call last):
File "/home/pi/robotvenv/lib/python3.11/site-packages/inventorhatmini/__init__.py", line 162, in __del__
self.ioe.reset()
^^^^^^^^
AttributeError: 'InventorHATMini' object has no attribute 'ioe'
This is because a failure has occurred before ioe is assigned. It would be more sensible to assign a None to this object until it is ready (in the class constructor), and then have an if guard on
self.ioe.reset() |
Eg:
def __del__(self):
if self.ioe:
self.ioe.reset()
It would still fall to the user to make sense of the device busy, but that might hopefully lead them to check for still-running processes.
Metadata
Metadata
Assignees
Labels
No labels