手机
当前位置:查字典教程网 >脚本专栏 >python >python创建线程示例
python创建线程示例
摘要:复制代码代码如下:importthreadingfromtimeimportsleepdeftest_func(id):foriinrang...

复制代码 代码如下:

import threading

from time import sleep

def test_func(id):

for i in range(0,5):

sleep(1)

print('thread %d is running %d' % (id,i))

threads = []

for i in range(0,3):

t = threading.Thread(target=test_func, args=(i,))

threads.append(t)

for t in threads:

t.start()

for t in threads:

t.join()

从输出结果可以看到,3个线程是交替的执行的

【python创建线程示例】相关文章:

Python 元类使用说明

python命令行参数sys.argv使用示例

python使用PyV8执行javascript代码示例分享

python 提取文件的小程序

python列表操作使用示例分享

python实现巡检系统(solaris)示例

python实现ip查询示例

Cython 三分钟入门教程

python求斐波那契数列示例分享

使用python绘制人人网好友关系图示例

精品推荐
分类导航