I have two functions, “one” and “two”. I want function “one” to run in the background as two runs. Basically, one executes, and while it’s waiting, execute two.
import time
def one(msg, a):
time.sleep(a)
print(msg)
def two(msg, a):
time.sleep(a)
print(msg)
one("Hello, ", 2) # Run this in the background as the other function runs
two("World!", 1)
I tried coroutines but it didn’t really work out for me because one ran after the other.
New contributor
i_suckatcode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.