import threading,time
def run(num):
print 'Hi ,im aaa',num
time.sleep(2)
print '--->'
for i in range(5):
t=threading.Thread(target=run,args=(i,))
t.start()
#以下为结果
[root@localhost ptest]# python threadt.py
Hi ,im aaa 0
Hi ,im aaa 1
Hi ,im aaa 2
Hi ,im aaa 3
Hi ,im aaa 4
--->
--->
--->
--->
--->
本文展示了一个简单的Python多线程程序示例。该程序创建了五个线程,每个线程输出一条信息并休眠两秒,最后打印完成标记。通过这个例子可以了解如何在Python中使用threading模块进行多线程编程。
1594

被折叠的 条评论
为什么被折叠?



