My team is trying to make multithreading possible in our code, but other responses in forums feature C++. I tried using Python’s official page, but it didn’t work, we are kind of stuck here. Any tips?
brain = Brain()
def thread_a():
count = 0
brain.screen.set_pen_color(Color.YELLOW)
while True:
brain.screen.print_at("%5d"%count, x=10, y=20)
count += 1
sleep(100)
def thread_b():
count = 0
brain.screen.set_pen_color(Color.GREEN)
while True:
brain.screen.print_at("%5d"%count, x=100, y=20)
count += 2
sleep(100)
Thread(thread_a)
Thread(thread_b)
does this mean that the documentation is wrong? It says to use thread = Thread(thread_a) and then run commands using that, but I don’t see how you would start the thread from that.
Would you do both?
thread = Thread(thread_a) Thread(thread_a)
so you create a variable and then run the thread?
A three year old topic ! however, documentation is not incorrect. The Thread class returns an object, you may choose to assign to a variable or not as you wish.
yep sorry about that lol
just to clear it up, defining the variable thread = Thread(thread_a) also starts the thread? How does that work?
Yes, it starts the thread.