I'm trying out multi-threading but can't seem to run two while loops simultaneously. Here is what I am trying:
import threading
def print_thread1():
while True:
print("Hello from thread1 !!!!!!!!!!!!!!")
def print_thread2():
while True:
print("Hello from thread2 !!!!!!!!!!!!!!")
thread1 = threading.Thread(target=print_thread1())
thread2 = threading.Thread(target=print_thread2())
thread1.start()
thread2.start()
#thread1.join()
#thread2.join()
This program outputs only:
Hello from thread1 !!!!!!!!!!!
constantly.
I commented out thread.join() methods because I read that it makes the main thread wait for one thread to complete before continuing. I'm looking to run both threads at the same time...
Could it be that while(1) loops are still a program blocker even using threading and instead I should look into multiprocessing?