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

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

  •  1
     
  •   miniyao · 2018-03-22 18:05:29 +08:00 · 3560 次点击
    这是一个创建于 2217 天前的主题,其中的信息可能已经有所发展或是发生改变。
    试了一下在 Thread 中新启一个任务,然后在这个任务里 time.sleep(60),然后整个应用的主线程就全阻塞了。
    7 条回复    2018-03-23 14:03:32 +08:00
    aisk
        1
    aisk  
       2018-03-22 18:29:54 +08:00
    之前就不会阻塞,你是不是在主线程里调用 join 或者 wait 了?
    miniyao
        2
    miniyao  
    OP
       2018-03-22 18:32:35 +08:00
    @aisk 想起来了,在这个 Thread 中有 IO 操作了,所以 GIL 不释放
    toono
        3
    toono  
       2018-03-22 22:49:46 +08:00
    @miniyao 我印象中 IO 操作是会释放 GIL 的。
    tkmiles
        4
    tkmiles  
       2018-03-23 00:05:11 +08:00
    发发代码来看看呀~~~
    凭空怎么看问题嘛
    tkmiles
        5
    tkmiles  
       2018-03-23 00:06:59 +08:00
    @aisk join 和 wait 都是等锁, C 代码会释放 gil 的
    wwqgtxx
        6
    wwqgtxx  
       2018-03-23 12:59:06 +08:00
    除非你调用了某个忘记释放 gil 的垃圾第三方库,否则不会出现这种情况的
    就算是你要 ctypes 和 cffi 来调用第三方 dll 的时候都一样会释放 gil
    Linxing
        7
    Linxing  
       2018-03-23 14:03:32 +08:00 via iPhone
    话说上次调用 telebot 就算这样锁死的 找了好久才发现问题 提 bug 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1025 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.