日日行,不怕千万里;常常做,不怕千万事|

__username

园龄:2年4个月粉丝:12关注:2

📂python
🔖Python
2024-01-24 10:00阅读: 210评论: 0推荐: 0

python多线程id获取

demo

import threading
import time
def print_thread_info(thread_name):
"""线程函数,打印线程名称和ID以及一些文本"""
for i in range(3):
time.sleep(1)
thread_id = threading.current_thread().ident
print(f"{thread_name} (ID: {thread_id}): 这是第 {i+1} 次打印")
# 创建线程列表
threads = []
# 创建并启动线程
for i in range(5):
thread = threading.Thread(target=print_thread_info, args=(f"线程{i+1}",))
thread.start()
threads.append(thread)
# 等待所有线程完成
for thread in threads:
thread.join()
print("所有线程已完成.")

output

posted @   __username  阅读(210)  评论(0编辑  收藏  举报
历史上的今天:
2023-01-24 59git常用命令

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起