summaryrefslogtreecommitdiff
path: root/docs/examples/userguide/fusedtypes/conditional_gil.pyx
blob: 473132f2e2031b5ee483c31b0562e13cb2852172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cimport cython

ctypedef fused double_or_object:
    double
    object

def increment(double_or_object x):
    with nogil(double_or_object is not object):
        # Same code handles both cython.double (GIL is released)
        # and python object (GIL is not released).
        x = x + 1
    return x

increment(5.0)  # GIL is released during increment
increment(5)    # GIL is acquired during increment