Let's Imagine the code below:
import threading
from time import sleep
def short_task():
sleep(5)
print("short task")
def long_task():
sleep(15)
print("long task")
while True:
st = threading.Thread(target=short_task())
lt = threading.Thread(target=long_task())
st.start()
lt.start()
st.join()
lt.join()
I have two functions that each take different times to process, in my approach above the output is going to be as below:
short task
long task
short task
long task
short task
long task
short task
long task
but the desired output is:
short task
short task
short task
long task
short task
short task
short task
long task
what is the best way to achieve this? one maybe dirty way is to remove the main while loop and put a while loop in each thread.
()from the targets.