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

Python 多线程/进程的两种使用方式的区别

  •  
  •   gtlions · 2018-09-28 15:23:48 +08:00 · 2585 次点击
    这是一个创建于 2029 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Python 多线程 /进程的两种使用方式:1、初始化类并传入可调用对象; 2、继承类,重载相关方法,这两种方式在使用场景或者其他情况上有什么区别?
    7 条回复    2018-09-28 21:11:48 +08:00
    xiaoshenke
        1
    xiaoshenke  
       2018-09-28 15:44:17 +08:00
    没有区别
    zeroDev
        2
    zeroDev  
       2018-09-28 15:45:21 +08:00 via Android
    waterloocode
        3
    waterloocode  
       2018-09-28 15:47:15 +08:00
    推荐多进程 GIL 是个坑
    ClutchBear
        4
    ClutchBear  
       2018-09-28 16:29:47 +08:00
    都不用,
    用 celery
    glacer
        5
    glacer  
       2018-09-28 16:41:14 +08:00
    @waterloocode IO 密集型的情况下,多线程基本不受 GIL 影响
    wizardforcel
        6
    wizardforcel  
       2018-09-28 16:56:46 +08:00
    区别就是原始的`run()`的行为是调用`target(*args, **kwargs)`。
    frostming
        7
    frostming  
       2018-09-28 21:11:48 +08:00
    一般你要加入别的属性 /方法的时候用继承的方法,否则能直接实例化干嘛多此一举
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3193 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:52 · PVG 21:52 · LAX 06:52 · JFK 09:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.