Python3 线程池 ThreadPoolExecutor

本文通过Python代码示例介绍了如何使用线程池执行大量任务,展示了ThreadPoolExecutor的用法,包括创建线程池、提交任务以及线程ID的获取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# coding: utf-8

import threading
import time
from concurrent.futures import ThreadPoolExecutor

def test():
    for i in range(5):
        print('running thread id : %d   now=%d'% (threading.get_ident(),i) )
        time.sleep(1)

#: 生成线程池  最大线程为50个
pool = ThreadPoolExecutor(5)

#: test
for i in range(100):
    pool.submit(test)     #提交并运行

转载于:https://my.oschina.net/tasker/blog/843055

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值