V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 3602 views
    This topic created in 2969 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
        1
    pusidun  
       Mar 11, 2018
    线程池
    ```
    pip install threadpool
    ```
    BBCCBB
        2
    BBCCBB  
       Mar 11, 2018
    ```python
    from multiprocessing.dummy import Pool as ThreadPool
    ```
    matsuz
        3
    matsuz  
       Mar 11, 2018 via iPhone   ❤️ 2
    concurrent.future.ThreadPoolExecutor
    jackqian
        4
    jackqian  
       Mar 11, 2018 via iPhone
    应该有类似 java 的线程池
    hanbaobao2005
        5
    hanbaobao2005  
       Mar 12, 2018
    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
        6
    Mojy  
       Mar 13, 2018
    @hanbaobao2005 这个应该是进程池吧?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1821 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 16:22 · PVG 00:22 · LAX 09:22 · JFK 12:22
    ♥ Do have faith in what you're doing.