Ask coding questions

← Back to all posts
Is there a way to run two pieces of code at once in python?
Zackyd00 (0)

So I want to create an achievement system for something im making, but want it to update as the main.py is running. Is there a way to do this?

Answered by Coder100 (18071) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18071)

threading is what you want!

from threading import Thread

def func1():
  # your achievement code

def func2():
  # your normal game code

t1 = Thread(target = func1)
t2 = Thread(target = func2)

t1.start()
t2.start()
robowolf (548)

Try threading. Here's an example. How it works is essentially you run a function along with you other code.