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
eccentric579
V2EX  ›  Python

在 ThreadPoolExecutor 里使用 subprocess 算多线程还是多进程

  •  
  •   eccentric579 · 2021-12-22 16:02:35 +08:00 · 2318 次点击
    这是一个创建于 827 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def doDownload(i):
        subprocess.run(['youtube-dl', '-o', f'{i[0]}.flv', f'{i[1]}'])
    
    
    if __name__ == "__main__":
        bvids = getvideoList()
        with concurrent.futures.ThreadPoolExecutor(max_workers=4) as ex:
            for item in bvids:
                ex.submit(doDownload, item)
    

    需要用到 subprocess.run()调用 shell 运行 youtube-dl

    5 条回复    2021-12-28 03:15:15 +08:00
    ArchieMeng
        1
    ArchieMeng  
       2021-12-22 16:46:50 +08:00 via Android
    看你怎么定义多进程。从操作系统来看,你这就是多进程。
    ClericPy
        2
    ClericPy  
       2021-12-22 22:04:17 +08:00
    之前试过子进程开多了确实利用了多核, 有多 pid 用了多个 CPU. 虽然在父进程里确实也是多线程...
    mingl0280
        3
    mingl0280  
       2021-12-23 05:02:37 +08:00 via Android
    肯定是多进程+线程啊,对于父进程来说,线程只是一个符号,你在多线程地管理多个符号而已。
    zepc007
        4
    zepc007  
       2021-12-27 09:26:44 +08:00
    多线程和多进程算是被你整明白了
    nikan999
        5
    nikan999  
       2021-12-28 03:15:15 +08:00
    算 多线程+多进程
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3324 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:35 · PVG 21:35 · LAX 06:35 · JFK 09:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.