推荐学习书目
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 · Dec 22, 2021 · 3403 views
    This topic created in 1615 days ago, the information mentioned may be changed or developed.
    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 replies    2021-12-28 03:15:15 +08:00
    ArchieMeng
        1
    ArchieMeng  
       Dec 22, 2021 via Android
    看你怎么定义多进程。从操作系统来看,你这就是多进程。
    ClericPy
        2
    ClericPy  
       Dec 22, 2021
    之前试过子进程开多了确实利用了多核, 有多 pid 用了多个 CPU. 虽然在父进程里确实也是多线程...
    mingl0280
        3
    mingl0280  
       Dec 23, 2021 via Android
    肯定是多进程+线程啊,对于父进程来说,线程只是一个符号,你在多线程地管理多个符号而已。
    zepc007
        4
    zepc007  
       Dec 27, 2021
    多线程和多进程算是被你整明白了
    nikan999
        5
    nikan999  
       Dec 28, 2021
    算 多线程+多进程
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3516 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:15 · PVG 19:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.