首页 > 代码库 > 使用 Python 进行线程编程
使用 Python 进行线程编程
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 进行线程编程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。