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

python 多线程

时间:2018-04-10 11:41:47      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:程序   star   UNC   name   sys   cti   __name__   tar   bin   

主程序:main.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import article
import threading

if __name__ == __main__:
    for i in range(10):
        if i % 2 == 0:
            t1 = threading.Thread(target = article.sleep, args = ("sleep function",))
            t1.start()
        else:
            article.publish("publish function")

模块程序:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import time


def sleep(msg):
    time.sleep(2)
    print msg

def publish(msg):
    print msg

if __name__ == __main__:
    publish("publish")
    sleep("sleep")

output

publish function
publish function
publish function
publish function
publish function
sleep functionsleep functionsleep functionsleep function



sleep function

 

python 多线程

标签:程序   star   UNC   name   sys   cti   __name__   tar   bin   

原文地址:https://www.cnblogs.com/yuanzhenliu/p/8777499.html

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