Debian Codegraph @

tools/tests/heartbeat/hb_gil.py

raw
1 """
2 Run this script in the qtconsole with one of:
3
4 %load hb_gil.py
5
6 or
7 %run hb_gil.py
8
9 Holding the GIL for too long could disrupt the heartbeat.
10
11 See Issue #1260: https://github.com/ipython/ipython/issues/1260
12
13 """
14
15 import sys
16 import time
17
18 from cython import inline
19
20 def gilsleep(t):
21 """gil-holding sleep with cython.inline"""
22 code = '\n'.join([
23 'from posix cimport unistd',
24 'unistd.sleep(t)',
25 ])
26 while True:
27 inline(code, quiet=True, t=t)
28 print(time.time())
29 sys.stdout.flush() # this is important
30
31 gilsleep(5)