This article example describes Python thread pool usage. Shared for your reference, as follows:
# -*- coding:utf-8 -*- #! python3 ''' Created on 2019-10-2 @author: Administrator ''' from import ThreadPoolExecutor,ProcessPoolExecutor import os,time,random def task(n): print('%s is runing' %()) ((1,3)) return n**2 if __name__ == '__main__': executor=ProcessPoolExecutor(max_workers=3) futures=[] for i in range(11): future=(task,i) (future) (True) print('+++>') for future in futures: print(())
Run results:
38704 is runing
38704 is runing
38704 is runing
38696 is runing
38696 is runing
38696 is runing
38696 is runing
38696 is runing
38712 is runing
38712 is runing
38712 is runing
+++>
0
1
4
9
16
25
36
49
64
81
100
Readers interested in more Python related content can check out this site's topic: theSummary of Python process and thread manipulation techniques》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Summary of Python string manipulation techniques》、《Python introductory and advanced classic tutorials》、《Python+MySQL Database Programming Tutorial for Beginnersand theSummary of common database manipulation techniques in Python》
I hope that what I have said in this article will help you in Python programming.