import _thread
import time
# Function for the first while loop
def loop1():
while True:
print("Thread 1 is running 1 sec")
time.sleep(1)
# Function for the second while loop
def loop2():
while True:
print("Thread 2 is running 2 sec")
time.sleep(2)
# Create and start two threads
_thread.start_new_thread(loop1, ())
_thread.start_new_thread(loop2, ())
# Main thread can also do some work
while True:
print("Main thread is running 3 sec")
time.sleep(3)