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

Python3.6 新版 Thread 还是会阻塞主线程吗?

  •  1
     
  •   miniyao · Mar 22, 2018 · 4436 views
    This topic created in 3112 days ago, the information mentioned may be changed or developed.
    试了一下在 Thread 中新启一个任务,然后在这个任务里 time.sleep(60),然后整个应用的主线程就全阻塞了。
    7 replies  •  2018-03-23 14:03:32 +08:00
    aisk
        1
    aisk  
       Mar 22, 2018
    之前就不会阻塞,你是不是在主线程里调用 join 或者 wait 了?
    miniyao
        2
    miniyao  
    OP
       Mar 22, 2018
    @aisk 想起来了,在这个 Thread 中有 IO 操作了,所以 GIL 不释放
    toono
        3
    toono  
       Mar 22, 2018
    @miniyao 我印象中 IO 操作是会释放 GIL 的。
    tkmiles
        4
    tkmiles  
       Mar 23, 2018
    发发代码来看看呀~~~
    凭空怎么看问题嘛
    tkmiles
        5
    tkmiles  
       Mar 23, 2018
    @aisk join 和 wait 都是等锁, C 代码会释放 gil 的
    wwqgtxx
        6
    wwqgtxx  
       Mar 23, 2018
    除非你调用了某个忘记释放 gil 的垃圾第三方库,否则不会出现这种情况的
    就算是你要 ctypes 和 cffi 来调用第三方 dll 的时候都一样会释放 gil
    Linxing
        7
    Linxing  
       Mar 23, 2018 via iPhone
    话说上次调用 telebot 就算这样锁死的 找了好久才发现问题 提 bug 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2798 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:34 · PVG 22:34 · LAX 07:34 · JFK 10:34
    ♥ Do have faith in what you're doing.