pgularski / pysm

Versatile and flexible Python State Machine library
http://pysm.readthedocs.io/
MIT License
73 stars 11 forks source link

deque Error in MicroPython within ESP32 #16

Open harryxu opened 4 days ago

harryxu commented 4 days ago

Env:

MicroPython v1.23.0 on 2024-06-02; Generic ESP32S3 module with ESP32S3

Error:

  File "/lib/pysm/pysm.py", line 474, in add_state
  File "/lib/pysm/pysm.py", line 784, in validate_add_state
  File "/lib/pysm/pysm.py", line 790, in _validate_state_already_added
  File "/lib/pysm/pysm.py", line 48, in __init__
TypeError: can't convert float to int

Through investigation, I found that the issue was caused by patch_deque in pysm using float('Inf') as the maxlen parameter for deque.

https://github.com/pgularski/pysm/blob/b48cbc79c06a70b84454bcbb24a5ac2095652c0b/pysm/pysm.py#L47-L48

The following is the code I ran in the ESP32 shell, which resulted in the same error.

>>> from collections import deque
iterable = []
maxlen = float('Inf')
>>> deque(iterable, maxlen)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert float to int
harryxu commented 4 days ago

@alhirzel Would it work correctly if we replace float('Inf') with sys.maxsize as the maxlen parameter?

harryxu commented 4 days ago

@alhirzel Would it work correctly if we replace float('Inf') with sys.maxsize as the maxlen parameter?

I tried; it won’t work and will cause a memory error.