Getting disconnected from webrepl when creating 2 threads

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
a-ha
Posts: 21
Joined: Sat Jun 27, 2020 10:42 pm

Getting disconnected from webrepl when creating 2 threads

Post by a-ha » Tue Jun 30, 2020 2:45 am

Hello,
I have tried the following simple threading program on the esp32 board via webrepl.

>>> import _thread
>>> def bar():
... _thread.start_new_thread(foo, (10, 200))
... _thread.start_new_thread(foo, (200, 400))
...
>>> bar()

I got disconnected from webrepl everytime I ran bar().
I understand _thread is still experimental, but this seems quite basic though.
Running 1 thread works fine btw.

a-ha

User avatar
jimmo
Posts: 1710
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Getting disconnected from webrepl when creating 2 threads

Post by jimmo » Tue Jun 30, 2020 1:04 pm

I don't see any reason why that doesn't work. What does "foo" do?

(Also, I would recommend looking at asyncio instead of thread if that's an option for you)

a-ha
Posts: 21
Joined: Sat Jun 27, 2020 10:42 pm

Re: Getting disconnected from webrepl when creating 2 threads

Post by a-ha » Tue Jun 30, 2020 6:06 pm

foo() is a simple function which print the integer between the 2 passed arguments.
Something like this:

def foo(a, b):
for i in range(a, b):
print i

Certainly broken with 2 threads, but works with only 1 thread.

Will look into asyncio.

Post Reply