Skip to content

Trapped local variable referenced before assignment in uasyncio. But it was assigned to. #5689

@gmos

Description

@gmos
Traceback (most recent call last):
  File "main.py", line 45, in <module>
  File "rmc/remcoo.py", line 94, in <module>
  File "uasyncio/core.py", line 177, in run_forever
  File "uasyncio/__init__.py", line 73, in wait
NameError: local variable referenced before assignment
MicroPython v1.12-184-gf8b2747 on 2020-02-20; ESP32 module (spiram) with ESP32

Code (uasyncio/__init__.py line 65 - 74)

    def wait(self, delay):
        if DEBUG and __debug__:
            log.debug("poll.wait(%d)", delay)
        # We need one-shot behavior (second arg of 1 to .poll())
        res = self.poller.ipoll(delay, 1)
        #log.debug("poll result: %s", res)
        # Remove "if res" workaround after
        # https://github.com/micropython/micropython/issues/2716 fixed.
        if res: 
            for sock, ev in res:
  • The trap was located on line 73, which is the "if res:" statement.
    But "res" was assigned to, immediately before this statement.
  • The bug is intermittent. There must have been 1000s calls of the wait method before this happened.
  • uasyncio (only core is used) was precompiled and frozen from the .../esp32/modules directory.
  • using a wrover with 16 MB flash.
  • MicroPython commit 1fccda0
  • This never has happened in the past. Seems to have started when I upgraded to the above version of MicroPython,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions