Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inconsistent thread behavior in different versions of MicroPython on ESP32 #15423

Closed
@flis-mateusz

Description

@flis-mateusz

Port, board and/or hardware

ESP-WROOM-32 (chip ESP32-D0WD-V3)

MicroPython version

  • [Works well] MicroPython v1.20.0 on 2023-04-26; ESP32 module with ESP32
  • [Bug] MicroPython v1.22.2 on 2024-02-22; Generic ESP32 module with ESP32
  • [Bug] MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32

Reproduction

import _thread
import time
        
def thread2task():
    print("thread 2 started")
    while True:
        pass


if __name__ == "__main__":
    _thread.start_new_thread(thread2task,())
        
    while 1:
        t = time.ticks_ms()
        time.sleep(1)
        print(time.ticks_ms() - t)

Expected behaviour

The main loop should consistently produce similar timing intervals regardless of the thread's state. For example, the sleep interval should be close to 1000ms as in version 1.20.

Output:

  • MicroPython v1.20.0 on 2023-04-26; ESP32 module with ESP32:
MPY: soft reboot
thread 2 started
1006
1010
1010
1010
1010
1010
1010
1010
1010
1010
[...]

Observed behaviour

Creating a simple thread in versions above 1.20 causes variable time intervals, which affects the timing accuracy of the main loop, suspends the connection to the computer, and often prevents the script from being restarted.

Output:

  • MicroPython v1.22.2 on 2024-02-22; Generic ESP32 module with ESP32:
MPY: soft reboot
thread 2 started
[Nothing else appears, this is where the script gets stuck]
  • MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32:
    Once I managed to get this result, other times nothing is printed, as in version 1.22.2
MPY: soft reboot
thread 2 started
1843
1230
1830
2060
1500
1500
2020
1980
2020
1980
[...]

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions