I have been trying to use threading for multiple instances.
here is my code:
from threading import Thread
from random import randint
import time
class MyThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
for x in range(1,5):
print(self.getName())
time.sleep(2)
mythread1 = MyThread()
mythread2 = MyThread()
mythread1.setName('Thread 1')
mythread2.setName('Thread 2')
When I start a thread. The output appears as expected.
mythread2.start()
Output: Thread 2
But if I run the second thread in a different cell. The output of earlier cell appears in the different cell.
mythread1.start()
Output: Thread 1 Thread 2 Thread 1 Thread 2 Thread 1 Thread 2 Thread 1
I want the output to appear in each of its cell. I think the multi-threading is happening but the output appears in the last cell.
Is there something wrong in my process? I need to get each cell to print its own output.
Thanks!