Python Thread - run method

Method Name:

run()

Method Overview:

The run method designates thread body. The run method gets it code on two ways.
One is when the run method is overridden in a subclass.
Another is when a callable object is passed as a target through the constructor of the Thread class.
Either way, one can formulate the run() method of a python thread.

from threading import Thread;

 

# A class that generates Square Numbers

class SuqareNumberSeriesThread(Thread):

    myCount = 0

 

    #Initialisation value received and assigned to myCount 

    def __init__(self,args):

        Thread.__init__(self)

        self.myCount = args

       

    # The run method is overridden to define the thread body

    def run(self):

        for i in range(1,self.myCount):

            print(i*i);           

           

SquareGenerator = SuqareNumberSeriesThread(args=(10))

SquareGenerator.start()

SquareGenerator.join()

 

myMac:PythonExamples macuser$ python RunMethodExample

1

4

9

16

25

36

49

64

81


Copyright 2024 © pythontic.com