adafruit / Adafruit_Python_PlatformDetect

MIT License
58 stars 233 forks source link

RecursionError when I am trying to 'import board' #96

Closed Petross404 closed 3 years ago

Petross404 commented 4 years ago

Hello friends, I am using the FT232H and I am following the example that is shown here but when I am trying to import board I get the following error:

 ~  python3
Python 3.8.5 (default, Jul 23 2020, 00:47:04) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/board.py", line 32, in <module>
    from adafruit_blinka.agnostic import board_id, detector
  File "/usr/lib/python3.8/site-packages/adafruit_blinka/agnostic/__init__.py", line 18, in <module>
    chip_id = detector.chip.id
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/chip.py", line 243, in __getattr__
    if self.id == attr:
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/chip.py", line 243, in __getattr__
    if self.id == attr:
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/chip.py", line 243, in __getattr__
    if self.id == attr:
  [Previous line repeated 973 more times]
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/chip.py", line 104, in id
    return self._linux_id()
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/chip.py", line 137, in _linux_id
    hardware = self.detector.get_cpuinfo_field("Hardware")
  File "/usr/lib/python3.8/site-packages/adafruit_platformdetect/__init__.py", line 54, in get_cpuinfo_field
    return match.group(1)
RecursionError: maximum recursion depth exceeded while calling a Python object
>>> 

I don't know if it's related with this error:

>>> from pyftdi.ftdi import Ftdi
>>> Ftdi().open_from_url('ftdi:///?')
Available interfaces:
  ftdi://ftdi:232h:1/1   (￿￿￿￿￿￿)

Please specify the USB device
 ✘  ~ 

But anyway, this works:

>>> from pyftdi.ftdi import Ftdi
>>> Ftdi.show_devices()
Available interfaces:
  ftdi://ftdi:232h:1/1   (￿￿￿￿￿￿)

>>> 

I followed the steps with udev rules and reloading, I re-connected the FT232H but nothing. Important note: I installed Blinka, Platform-Detect, pyftdi and the rest with Portage on Gentoo Linux and not with pip3.

Also pyusb is installed along with pyftdi and the following packages:

dev-python/Adafruit-Blinka:0
dev-python/adafruit-circuitpython-mcp230xx:0
dev-python/Adafruit-PlatformDetect:0
dev-python/Adafruit-PureIO:0

Any ideas what I could be missing here? Thank you in advance.

makermelissa commented 4 years ago

Hmm, mysterious. What do you get when you run the script here? https://github.com/adafruit/Adafruit_Python_PlatformDetect/blob/master/bin/detect.py

makermelissa commented 3 years ago

Could you please try again with the latest version of PlatformDetect? I added some caching, so I'm hoping that may have fixed it.

Petross404 commented 3 years ago

Could you please try again with the latest version of PlatformDetect? I added some caching, so I'm hoping that may have fixed it.

I will as soon as my shifts at work aren't changed constantly :) Thank you for the interest.

CrazyIvan359 commented 3 years ago

I also experienced this issue running v2.17.0 on Ubuntu 20.04 inside a VBox VM. Works fine on RPi3B and Orange Pi Zero LTS I have though.

The problem is the overriden __getattr__ in chip.Chip. I'm making a PR to fix it.

jczacharia commented 1 year ago

It looks like this issue is still ongoing. I'm using a Google Coral dev board with balena OS and running a py file with import board gives me this:

File "/app/hardware-logic/api.py", line 34, in <module>
  import board
File "/usr/local/lib/python3.9/dist-packages/board.py", line 22, in <module>
    from adafruit_blinka.agnostic import board_id, detector
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/agnostic/__init__.py", line 21, in <module>
  chip_id = detector.chip.id
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/chip.py", line 419, in __getattr__
    if self.id == attr:
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/chip.py", line 419, in __getattr__
    if self.id == attr:
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/chip.py", line 419, in __getattr__
    if self.id == attr:
  [Previous line repeated 974 more times]
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/chip.py", line 158, in id
    self._chip_id = self._linux_id()
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/chip.py", line 293, in _linux_id
    hardware = self.detector.get_cpuinfo_field("Hardware")
File "/usr/local/lib/python3.9/dist-packages/adafruit_platformdetect/__init__.py", line 44, in get_cpuinfo_field
    cpuinfo = infile.read().split("\n")   RecursionError: maximum recursion depth exceeded while calling a Python object

I'm using these dependencies

pandas==1.4.1
ipython==8.4.0
smbus2==0.4.2
python-periphery==2.4.1
adafruit-blinka==8.19.0
adafruit-circuitpython-vl53l0x==3.6.9

I'm not sure if this is a balena issue I'm still encountering this. Any insight on a fix?

jczacharia commented 1 year ago

Apparently, this infinite loop happens when no chip or board can be detected. Balena deletes data from /proc/cpuinfo and thus the infinite loop. There should be a better way to handle this instead of getting this recursion error but for anyone that has this issue, you might need to fork the repo and manually set the chip and board ids manually.

CrazyIvan359 commented 1 year ago

@jczacharia can you provide the output of cat /proc/cpuinfo for your board

jczacharia commented 1 year ago

@CrazyIvan359

processor       : 0
BogoMIPS        : 16.66
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 1
BogoMIPS        : 16.66
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 2
BogoMIPS        : 16.66
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

processor       : 3
BogoMIPS        : 16.66
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 4

I'm using a Google Coral and the chip and board should be set to:

chip_id = "IMX8MX"
board_id = "CORAL_EDGE_TPU_DEV"

Note I took a look at your fix #104 and that worked (as in no more infinite recursion) but it failed to recognize the chip and board and threw an appropriate error saying such.

CrazyIvan359 commented 1 year ago

Yeah they really strip a lot of info out of that. What about cat /proc/device-tree/compatible

jczacharia commented 1 year ago
fsl,imx8mq-phanbellfsl,imx8mq

With no line break at eof

CrazyIvan359 commented 1 year ago

Ok this is a different issue but it ends up giving the same symptoms because PlatformDetect cannot identify your board. Please open a new a new issue and reference one of your posts in this issue (click the 3 dots on your post, there is an option to Reference in new issue).

Since I've come this far I'm working on a little PR to get this board to be detected. You'll see my PR tagged in your new issue when I push it.