Skip to content

Instantly share code, notes, and snippets.

@Cyan101
Created January 3, 2022 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cyan101/2a097b5278b7bc133f9671d52e7fdaf2 to your computer and use it in GitHub Desktop.
Save Cyan101/2a097b5278b7bc133f9671d52e7fdaf2 to your computer and use it in GitHub Desktop.
Testing threading on micropython
import machine
import utime
import _thread
def threadStart(x):
while True:
print(f"Thread {x} here!")
utime.sleep(1)
_thread.start_new_thread(threadStart(1), ())
print("ayyy")
print("lmao")
@Cyan101
Copy link
Author

Cyan101 commented Jan 3, 2022

my thread runs but the follow text/code does not, this is for the pico which has 2 cores and trying to get dual threads running

@Cyan101
Copy link
Author

Cyan101 commented Jan 3, 2022

maybe due to repl being on one core?

@Cyan101
Copy link
Author

Cyan101 commented Jan 3, 2022

seems it doesnt like having the functions args in like that, and even if one arg is being passed it must be in a tuple, example working below:

import machine
import utime
import _thread

def threadStart(x):
    print("\nyo")
    utime.sleep(2)
    print("ayy")
        
        
_thread.start_new_thread(threadStart, (1,))
print("hey")
utime.sleep(3)
print("gg")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment