首页 > 编程语言 > 详细

python 线程,进程28原则

时间:2018-06-18 15:38:53      阅读:178      评论:0      收藏:0      [点我收藏+]

先上框架

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原则

原文:https://www.cnblogs.com/zenan/p/9188521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!