Two ways of calling thread way

Directly call 

Import Threading Import Time   DEF sayHi (NUM): # define the function of each thread to run       Print (
" running ON Number:% S "  % NUM)       the time.sleep ( . 3 )   IF  the __name__ ==  ' __main__ ' :       T1  = of the threading.Thread (target = sayHi, args = ( . 1 ,)) # generates a thread instance     T2  = of the threading.Thread (target = sayHi, args = ( 2 ,)) # generates another thread instance       t1.start () # start thread     t2.start () # start another thread       print (t1.getName ()) # get the thread name     print (t2.getName ()) inherited invocation

Threading Import
Import Time
 
 
class MyThread (threading.Thread):
    DEF __init __ (Self, NUM):
        threading.Thread .__ the init __ (Self)
        self.num = NUM
 
    DEF RUN (Self): # define each thread to run and function
 
        print ( "ON running Number:% S"% self.num)
 
        the time.sleep (. 3)
 
IF the __name__ == '__main__':
 
    T1 = the MyThread (. 1)
    T2 = the MyThread (2)
    t1.start ()
    t2.start ()

 

Guess you like

Origin www.cnblogs.com/wutanghua/p/11671304.html