Create Thread without Inheritance in Python

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

import time
from threading import *

class MyThread:
    def display(self,n):
        print(current_thread().getName())
        for i in range(1,n+1):
            print(i)
            time.sleep(1)

# Main Thread

M1=MyThread()
T1=Thread(target=M1.display,args=(5,),name="First")
T2=Thread(target=M1.display,args=(10,),name="Second")
T1.start()
T2.start()

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *