没有合适的资源?快使用搜索试试~ 我知道了~
python GIL 详细说明 由python cookbook作者编写
资源推荐
资源详情
资源评论
Copyright (C) 2010, David Beazley, http://www.dabeaz.com
Understanding the
Python GIL
1
David Beazley
http://www.dabeaz.com
Presented at PyCon 2010
Atlanta, Georgia
Copyright (C) 2010, David Beazley, http://www.dabeaz.com
Introduction
•
As a few of you might know, C Python has a
Global Interpreter Lock (GIL)
2
>>> import that
The Unwritten Rules of Python
1. You do not talk about the GIL.
2. You do NOT talk about the GIL.
3. Don't even mention the GIL. No seriously.
...
•
It limits thread performance
•
Thus, a source of occasional "contention"
Copyright (C) 2010, David Beazley, http://www.dabeaz.com
An Experiment
•
Consider this trivial CPU-bound function
def countdown(n):
while n > 0:
n -= 1
3
•
Run it once with a lot of work
COUNT = 100000000 # 100 million
countdown(COUNT)
•
Now, subdivide the work across two threads
t1 = Thread(target=countdown,args=(COUNT//2,))
t2 = Thread(target=countdown,args=(COUNT//2,))
t1.start(); t2.start()
t1.join(); t2.join()
Copyright (C) 2010, David Beazley, http://www.dabeaz.com
A Mystery
•
Performance on a quad-core MacPro
4
Sequential
Threaded (2 threads)
•
Performance if work divided across 4 threads
•
Performance if all but one CPU is disabled
: 7.8s
: 15.4s (2X slower!)
Threaded (4 threads) : 15.7s (about the same)
Threaded (2 threads)
Threaded (4 threads)
: 11.3s (~35% faster than running
: 11.6s with all 4 cores)
•
Think about it...
Copyright (C) 2010, David Beazley, http://www.dabeaz.com
This Talk
•
An in-depth look at threads and the GIL that
will explain that mystery and much more
•
Some cool pictures
•
A look at the new GIL in Python 3.2
5
剩余61页未读,继续阅读
资源评论
tuxl_c_s_d_n
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功