Python threading 如何控制线程数?

2018 年 3 月 11 日
 suannva

if name == "main": file = open("mssql.ip",'r') for ip in file.readlines(): ip = ip.strip('\n') t1 = Thread(target=content,args=(ip,)) t1.start() 写一个东西 目前是这么用的 怎么控制线程数量

3512 次点击
所在节点    Python
6 条回复
pusidun
2018 年 3 月 11 日
线程池
```
pip install threadpool
```
BBCCBB
2018 年 3 月 11 日
```python
from multiprocessing.dummy import Pool as ThreadPool
```
matsuz
2018 年 3 月 11 日
concurrent.future.ThreadPoolExecutor
jackqian
2018 年 3 月 11 日
应该有类似 java 的线程池
hanbaobao2005
2018 年 3 月 12 日
https://segmentfault.com/a/1190000000414339

from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool()
pool = ThreadPool(4) # Sets the pool size to 4
results = pool.map(func, paras)
pool.close()
pool.join()
Mojy
2018 年 3 月 13 日
@hanbaobao2005 这个应该是进程池吧?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/436980

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX