Python线程类首先是一个类

ITWYY

关注

阅读 98

2023-06-09


直接用代码说话,有关基本概念可查阅操作系统有关书籍和《Python程序设计》(董付国编著,清华大学出版社,2015.8第一版)。

import threading 

 
 
 
 

  class myThread(threading.Thread): 

 
 
 
 

      def __init__(self, threadName): 

 

          threading.Thread.__init__(self) 

 

          self.name = threadName 

 

           

 

      def run(self): 

 

          print('In run:', self.name) 

 
 
 
 

      def output(self): 

 

          print('In output:', self.name) 

 
 
 
 

  t = myThread('test') 

 

  t.output() 

 
 t.start()

运行结果如图所示:

Python线程类首先是一个类_Python

精彩评论(0)

0 0 举报