推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
suannva
V2EX  ›  Python

Python threading 如何控制线程数?

  •  
  •   suannva · Mar 11, 2018 · 4149 views
    This topic created in 3161 days ago, the information mentioned may be changed or developed.

    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() 写一个东西 目前是这么用的 怎么控制线程数量

    6 replies  •  2018-03-13 17:52:09 +08:00
    pusidun
    pusidun
    Mar 11, 2018
    1
    线程池
    ```
    pip install threadpool
    ```
    BBCCBB
    BBCCBB
    Mar 11, 2018
    2
    ```python
    from multiprocessing.dummy import Pool as ThreadPool
    ```
    matsuz
    matsuz
    Mar 11, 2018 via iPhone❤️2
    3
    concurrent.future.ThreadPoolExecutor
    jackqian
    jackqian
    Mar 11, 2018 via iPhone
    4
    应该有类似 java 的线程池
    hanbaobao2005
    hanbaobao2005
    Mar 12, 2018
    5
    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
    Mojy
    Mar 13, 2018
    6
    @hanbaobao2005 这个应该是进程池吧?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1361 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 20:19 · PVG 04:19 · LAX 12:19 · JFK 15:19
    ♥ Do have faith in what you're doing.