← index #7862Issue #12694
Off-topic · high · value 0.469
QUERY · ISSUE

How use _thread library?

openby wangdy-codeopened 2021-09-27updated 2021-10-15
port-esp32

### borad:esp32

I expect to use this library to create a thread to detect whether a thread with the same function has been created and delete the previous thread with the same function.

CANDIDATE · ISSUE

start_new_thread() can't create thread in mpython 1.21

closedby enesbcsopened 2023-10-15updated 2023-10-15
bug

Sample code used from:
https://mpython.readthedocs.io/en/master/library/micropython/_thread.html

import _thread
import time

def th_func(delay, id):
    while True:
        time.sleep(delay)
        print('Running thread %d' % id)

for i in range(2):
    _thread.start_new_thread(th_func, (i + 1, i))

MicroPython v1.21.0 on 2023-10-06; Generic ESP32 module with SPIRAM with ESP32

Traceback (most recent call last):
File "<stdin>", line 10, in <module>
OSError: can't create thread

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied