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

使用 Python 进行线程编程

时间:2017-04-29 16:17:20      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:time   rar   color   编程   date   pre   import   logs   cli   

w

 

 

使用 Python 进行线程编程
https://www.ibm.com/developerworks/cn/aix/library/au-threadingpython/index.html

import threading
import datetime
class ThreadClass(threading.Thread):
    def run(self):
        now = datetime.datetime.now()
        print "%s says Hello World at time: %s" % (self.getName(),now)
for i in range(2):
    t = ThreadClass()
    t.start()

 

 

C:\>python E:\MATHpyCLI\au-threadingpython.py
Thread-1 says Hello World at time: 2017-04-29 15:07:00.141000Thread-2 says Hello World at time: 2017-04-29 15:07:00.143000



C:\>python E:\MATHpyCLI\au-threadingpython.py
Thread-1 says Hello World at time: 2017-04-29 15:07:02.312000Thread-2 says Hello World at time: 2017-04-29 15:07:02.313000



C:\>python E:\MATHpyCLI\au-threadingpython.py
Thread-1 says Hello World at time: 2017-04-29 15:07:03.116000
 Thread-2 says Hello World at time: 2017-04-29 15:07:03.118000

 

使用 Python 进行线程编程

标签:time   rar   color   编程   date   pre   import   logs   cli   

原文地址:http://www.cnblogs.com/yuanjiangw/p/6785228.html

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