当前位置:首页 » 编程语言 » pythonfor多线程

pythonfor多线程

发布时间: 2025-09-14 05:53:56

python如何并列运行两个for循环

需要用到多线程
#!/usr/bin/python3

import _thread
import time

# 为线程定义一个函数
def print_time( threadName, delay):
....count = 0
....while count < 5:
........time.sleep(delay)
........count += 1
........print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

# 创建两个线程
try:
...._thread.start_new_thread( print_time, ("Thread-1", 2, ) )
...._thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
....print ("Error: 无法启动线程")

while 1:
....time.sleep(5)
....print('is main ')

热点内容
pythonif写一行 发布:2025-09-14 07:41:39 浏览:992
lua存储数据 发布:2025-09-14 07:33:05 浏览:111
教你如何选配置车 发布:2025-09-14 07:32:21 浏览:417
行李箱自带的密码是多少 发布:2025-09-14 07:27:40 浏览:278
ps2020版本怎么调整存储盘 发布:2025-09-14 07:20:28 浏览:860
奥迪a6哪个配置最保值 发布:2025-09-14 07:11:53 浏览:986
android查看文件 发布:2025-09-14 07:00:37 浏览:291
carlyle压缩机 发布:2025-09-14 06:16:51 浏览:978
支持ftp免费空间 发布:2025-09-14 06:05:16 浏览:208
android横屏生命周期 发布:2025-09-14 05:55:27 浏览:423