直接用代码说话,有关基本概念可查阅操作系统有关书籍和《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()
运行结果如图所示: