Destructor for InventorHATMini assumes ioe device created

Aperta
#13 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@dannystaple ci sta già lavorando.

Dal 8/7/2025.

  • #15 di @dannystaple — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
embedded-iot

Direzione di ricerca

Open inventorhatmini/init.py and inspect the constructor around the assignment to ioe and the del method at line 162. Initialize ioe before device setup and ensure the destructor only resets it when it exists. Reproduce the failed device setup if possible and confirm cleanup no longer raises AttributeError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 https://github.com/pimoroni/inventorhatmini-python/blob/de6f82f3f5dc5b227f8ff396cab1f35bf506b6b6/inventorhatmini/__init__.py#L162.

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.

Lingua principale
Python
Stelle
7
Fork
5
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pimoroni/inventorhatmini-python

Tutte le issue di pimoroni/inventorhatmini-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.