码迷,mamicode.com
首页 > 编程语言 > 详细

python 线程,进程28原则

时间:2018-06-18 16:05:05      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:threading   port   fun   eth   googl   star   RoCE   python   函数   

先上框架

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

标签:threading   port   fun   eth   googl   star   RoCE   python   函数   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!