我完全是偶然发现了一个可以胜任这一任务的工具:gil_load。
实际上,这个工具是在我发问题之后发布的。
干得好,@chrisjbillington。
>>> import sys, math
>>> import gil_load
>>> gil_load.init()
>>> gil_load.start(output = sys.stdout)
>>> for x in range(1, 1000000000):
... y = math.log(x**math.pi)
[2017-03-15 08:52:26] GIL load: 0.98 (0.98, 0.98, 0.98)
[2017-03-15 08:52:32] GIL load: 0.99 (0.99, 0.99, 0.99)
[2017-03-15 08:52:37] GIL load: 0.99 (0.99, 0.99, 0.99)
[2017-03-15 08:52:43] GIL load: 0.99 (0.99, 0.99, 0.99)
[2017-03-15 08:52:48] GIL load: 1.00 (1.00, 1.00, 1.00)
[2017-03-15 08:52:52] GIL load: 1.00 (1.00, 1.00, 1.00)
<...>
>>> import sys, math
>>> import gil_load
>>> gil_load.init()
>>> gil_load.start(output = sys.stdout)
>>> for x in range(1, 1000000000):
... with open('/dev/null', 'a') as f:
... print(math.log(x**math.pi), file=f)
[2017-03-15 08:53:59] GIL load: 0.76 (0.76, 0.76, 0.76)
[2017-03-15 08:54:03] GIL load: 0.77 (0.77, 0.77, 0.77)
[2017-03-15 08:54:09] GIL load: 0.78 (0.78, 0.78, 0.78)
[2017-03-15 08:54:13] GIL load: 0.80 (0.80, 0.80, 0.80)
[2017-03-15 08:54:19] GIL load: 0.81 (0.81, 0.81, 0.81)
[2017-03-15 08:54:23] GIL load: 0.81 (0.81, 0.81, 0.81)
[2017-03-15 08:54:28] GIL load: 0.81 (0.81, 0.81, 0.81)
[2017-03-15 08:54:33] GIL load: 0.80 (0.80, 0.80, 0.80)
<...>