start_new_thread

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
arj
Posts: 9
Joined: Wed Feb 03, 2021 5:45 pm

start_new_thread

Post by arj » Mon Feb 08, 2021 3:11 pm

I'm struggling to get code running on the second core.

A couple of questions:

1) How do you stop the code running once it's started with start_new_thread? Is it enough to break out of the function? When I do this I can't seem to use start_new_thread a second time.

2) Am I right to assume that you cannot pass a single parameter to a function with start_new_thread? I get a tuple error when I try sending just one.

Is any additional functionality being considered for utilising the second Pico core (I'm using v1.14)?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: start_new_thread

Post by Roberthh » Mon Feb 08, 2021 3:31 pm

How do you stop the code running once it's started with start_new_thread?
Call _thread.exit()
Am I right to assume that you cannot pass a single parameter to a function with start_new_thread? I get a tuple error when I try sending just one.
You can pass a single element tuple: (value, )

arj
Posts: 9
Joined: Wed Feb 03, 2021 5:45 pm

Re: start_new_thread

Post by arj » Mon Feb 08, 2021 5:11 pm

Thanks for the single element tuple syntax. That was one combination I didn't try.

I'm not having much luck trying to stop code running on the second core. Do I call the _thread.exit() from the main core or from the background running function?

Are you able to give a short example (on a Pico).

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: start_new_thread

Post by Roberthh » Mon Feb 08, 2021 7:09 pm

_thread.exit() will be called from within the newly started thread.

Post Reply