File: hb_gil.py

package info (click to toggle)
ipython 8.35.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 11,900 kB
  • sloc: python: 42,442; sh: 376; makefile: 243
file content (31 lines) | stat: -rw-r--r-- 574 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Run this script in the qtconsole with one of:

    %load hb_gil.py

or
    %run hb_gil.py

Holding the GIL for too long could disrupt the heartbeat.

See Issue #1260: https://github.com/ipython/ipython/issues/1260

"""

import sys
import time

from cython import inline

def gilsleep(t):
    """gil-holding sleep with cython.inline"""
    code = '\n'.join([
        'from posix cimport unistd',
        'unistd.sleep(t)',
    ])
    while True:
        inline(code, quiet=True, t=t)
        print(time.time())
        sys.stdout.flush() # this is important

gilsleep(5)