Destructor for InventorHATMini assumes ioe device created

オープン
#13 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

@dannystaple がすでに取り組んでいます。

2025年7月8日 から。

  • #15 @dannystaple による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
embedded-iot

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
7
フォーク
5
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pimoroni/inventorhatmini-python のほかの issue

pimoroni/inventorhatmini-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。