I'm learning python 3 and I watched this tutorial about threading:
I tested the example code but for some reason the result is sort of weird.
import threading
class Messenger(threading.Thread):
def run(self):
for _ in range(10):
print(threading.currentThread().getName())
m1 = Messenger(name="Send Messages")
m2 = Messenger(name="Receive Messages")
m1.start()
m2.start()
I was expecting the program to print out "Send Messages" and "Receive Messages" on a sort of random order, but this what happened, and I'm not quite sure why:
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Send MessagesReceive Messages
Can somebody explain to me why were the results printed this way? Thanks for any help given!