python创建线程示例
时间:2021-07-21 00:20:37
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,线程
0
投稿
猜你喜欢
python之pkl文件的用法及说明
2021-02-21 21:44:57
python matplotlib.pyplot.plot()参数用法
2023-07-13 17:39:48
pandas如何解决excel科学计数法问题
2023-12-20 05:06:20
用asp判断某IP是否属于某网段的另类算法
2007-09-28 12:33:00
python通过http上传文件思路详解
2022-02-08 12:48:30
Python入门(六)Python数据类型
2022-08-19 21:09:11
python编写adb截图工具的实现源码
2021-03-24 08:50:15
python编写图书管理系统
2022-04-12 11:07:21
用Python实现等级划分
2022-10-11 23:45:21
IE下文本被折行的解决方案
2009-06-28 16:13:00
Django实现上传图片功能
2022-01-06 13:57:44
模式化窗口
2009-06-18 18:41:00
Python读写JSON文件的操作详解
2021-03-22 11:46:35
使用javascript提交form表单方法汇总
2023-08-23 09:03:48
python 实现定时任务的四种方式
2023-06-28 14:37:27
Python中使用ipython的详细教程
2023-05-28 13:14:48
CSS结合js实现动态更换皮肤
2007-07-14 10:01:00
python map比for循环快在哪
2021-06-16 09:39:04
一篇文章教你用Python实现一键文件重命名
2022-09-21 20:18:38
php 方便水印和缩略图的图形类
2023-10-15 15:31:28