Skip to main content

线程池, 固定指定数量的线程来执行任务, 避免重复创建和销毁线程时的资源消耗

Project description

线程池, 固定指定数量的线程来执行任务, 避免重复创建和销毁线程时的资源消耗

如果任务数量超过线程数量, 超出的任务会等待有正在执行的任务执行完毕后, 在有空闲线程时才会执行

if __name__ == '__main__':
import time
import threading

p = ThreadPool(2)

def fun(a, c):
print(a, '开始', time.strftime(' %H:%M:%S', time.localtime()))
for i in range(c):
print(a, ' 结束', time.strftime(' %H:%M:%S', time.localtime()))

fun('aa', 100)
fun('bb', 100)
fun('cc', 100)
fun('dd', 100)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for zthreadpool, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size zthreadpool-1.0.1-py3-none-any.whl (16.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size zthreadpool-1.0.1.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page