python 线程,进程28原则
Posted 逗比青年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 线程,进程28原则相关的知识,希望对你有一定的参考价值。
先上框架
from threading import Thread from multiprocessing import Process class MyThread(Thread): def __init__(self, func): super(MyThread,self).__init__() self.func = func def run(self): self.func() class MyProcess(Process): def __init__(self, func): super(MyProcess,self).__init__() self.func = func def run(self): self.func()
传入类的入口函数,即可实现多线程
baidu = Baidu() sogou = Sogou() google = Google() baiduThread = MyThread(baidu.run) sogouThread = MyThread(sogou.run) googleThread = MyThread(google.run) # 线程开启 baiduThread.start() sogouThread.start() googleThread.start() # 主线程等待子线程 baiduThread.join() sogouThread.join() googleThread.join()
以上是关于python 线程,进程28原则的主要内容,如果未能解决你的问题,请参考以下文章