python-3.x – Is it possible to run two loops at the same time in python?


I was wanting to make a kind of game where you buy some things that help you profit, and you would have an amount you earn per second, but I don't know if I can run two loops (one to make the interaction with the player and the other to add an amount of money to the player per second) in python, if anyone knows, can you help me?


You can use threads. Using it allows you to parallelize tasks in your program. If you use this solution, if there is any variable that is modified by more than one thread, I recommend that you create a lock. The reason is that, without a lock, the variable can take on a different value than desired.

Scroll to Top