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
本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17983978
分类:
标签:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2023-01-24 59git常用命令