0
点赞
收藏
分享

微信扫一扫

Python线程类首先是一个类

ITWYY 2023-06-09 阅读 98


直接用代码说话,有关基本概念可查阅操作系统有关书籍和《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 条评论