V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Trim21
V2EX  ›  Python

有没有类似 node 中 async 一样易用的多线程库?

  •  
  •   Trim21 ·
    Trim21 · 2016-08-17 16:32:32 +08:00 · 2075 次点击
    这是一个创建于 2829 天前的主题,其中的信息可能已经有所发展或是发生改变。
    之前用 node 做爬虫的时候一直用的是 async 控制并发数,到 Python 下面看了看多线程,控制线程数量有些麻烦,有没有类似 async 这样封装好的只要传递一个参数 list 和函数,能根据设定的限制自动控制并发线程数的库或者包?
    7 条回复    2016-08-18 11:14:05 +08:00
    bigtan
        1
    bigtan  
       2016-08-17 16:58:10 +08:00   ❤️ 1
    multiprocessing pool
    shyling
        2
    shyling  
       2016-08-17 17:38:18 +08:00   ❤️ 1
    不是有 concurrent.futures 么?
    janxin
        3
    janxin  
       2016-08-17 19:47:40 +08:00 via iPhone
    node 的 async 不是还是单线程的么?
    Trim21
        4
    Trim21  
    OP
       2016-08-17 19:55:45 +08:00 via Android
    @janxin 其实我的意思是,彻底参数列表和函数就可以并行的。
    其实现在也是在写爬虫,要并行也是因为等 IO
    eloah
        5
    eloah  
       2016-08-17 22:01:55 +08:00
    node 本身不就是单线程的吗......
    话说,python 下也有 async 这个库......
    multiprocessing 就好啦
    latyas
        6
    latyas  
       2016-08-18 08:23:13 +08:00 via iPhone
    @Trim21 multiprocessing
    爬虫可用 tornado 或者 asyncio 这是异步 io 的库 速度可以很快
    Zuckonit
        7
    Zuckonit  
       2016-08-18 11:14:05 +08:00
    多线程: from multiprocessing.dummy import Pool as ThreadPool
    有个第三方库: threadpool
    可以考虑下协程: gevent
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5638 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:02 · PVG 15:02 · LAX 00:02 · JFK 03:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.