推荐学习书目
› 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
beeeta
V2EX  ›  Python

Python 多进程能实现并行并突破 GIL 的限制在多个 CPU 上运行吗?一个 Python 解释器有一个 GIL 还是一个进程有一个 GIL 呢?

  •  
  •   beeeta · Dec 5, 2017 · 5327 views
    This topic created in 3255 days ago, the information mentioned may be changed or developed.
    10 replies  •  2018-04-04 09:26:20 +08:00
    wellsc
    wellsc
    Dec 5, 2017
    1
    多进程没有 GIL 限制
    misaka19000
    misaka19000
    Dec 5, 2017
    2
    一个进程一个 GIL
    jimzhong
    jimzhong
    Dec 5, 2017
    3
    可以实现
    jingniao
    jingniao
    Dec 5, 2017 via Android
    4
    一个进程一个解释器一个 GIL,多进程就有多个解释器多个 GIL
    ArthurMarcel
    ArthurMarcel
    Dec 5, 2017
    5
    当然是一个进程一个 GIL 了,不然开多进程提升效率是为什么?
    kunluanbudang
    kunluanbudang
    Dec 5, 2017
    6
    据我了解到的 Python 社区解决此类问题的套路
    重 IO
    1. 多线程还是可以用用的
    2. 协程 /asyncio/gevent 等等
    3. 多进程,每个核放一个 Python 进程
    4. PyPy


    重 CPU
    1. 多进程
    2. 关键模块用 C 重写, 规避 GIL 的限制
    3. PyPy
    kuro1
    kuro1
    Dec 6, 2017
    7
    可以吃满 CPU,用 htop 看非常爽
    everhythm
    everhythm
    Dec 6, 2017
    8
    不涉及 shell 的话可以用 py 带的 multiProcess 里面的 pool 实现进程池
    pool 默认是开 机器 cpu 个数的进程
    beeeta
    beeeta
    OP
    Dec 6, 2017
    9
    谢谢各位的回复!:)
    wizardforcel
    wizardforcel
    Apr 4, 2018
    10
    它相当于把 GIL 也复制了一份(因为是不同的 VA )。

    任何锁如果复制一份都会失效的。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1381 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 21:23 · PVG 05:23 · LAX 13:23 · JFK 16:23
    ♥ Do have faith in what you're doing.