首页 > 编程语言 > 详细

使用两种方式编写多线程程序?

时间:2019-01-01 21:34:18      阅读:142      评论:0      收藏:0      [点我收藏+]
# 方案1
from threading import Thread
import time

class Sayhi(Thread):
    def __init__(self,name):
        super().__init__()
        self.name=name
    def run(self):
        time.sleep(2)
        print(‘%s say hello‘ % self.name)

if __name__ == ‘__main__‘:
    t = Sayhi(‘妹子‘)
    t.start()
    print(‘主线程‘)
# 方案2
from threading import Thread
import time
def sayhi(name):
    time.sleep(2)
    print(‘%s say hello‘ %name)

if __name__ == ‘__main__‘:
    t=Thread(target=sayhi,args=(‘apollo‘,))
    t.start()
    print(‘主线程‘)

 

使用两种方式编写多线程程序?

原文:https://www.cnblogs.com/apollo1616/p/10206044.html

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