from multiprocessing import Process, Pool
import time
all_task = []
thread_pool_count = 0
def abc1(i, j):
time.sleep(20)
def abc2(i, j):
time.sleep(10)
def abc3(i, j):
time.sleep(5)
#thread_pool = ThreadPoolExecutor(10)
thread_pool = Pool(processes = 10)
def print_error(value):
print("Process pool report error: {}".format(value))
i = 0
j = 0
thread_pool.apply_async(
func = abc1,
args = (
i,
j
),
error_callback = print_error
)
thread_pool.apply_async(
func = abc2,
args = (
i,
j
),
error_callback = print_error
)
thread_pool.apply_async(
func = abc3,
args = (
i,
j
),
error_callback = print_error
)
while True:
print(len(thread_pool._cache))
time.sleep(1)
结论:
print(len(thread_pool._cache))
打印进程池内正在运行的进程个数