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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
Test to verify PyO3 allow_threads() behavior with assume_gil_acquired().
This helps us understand if the pattern we're using actually releases the GIL.
"""
"""Simple test of GIL release via event signaling."""
= . / / / /
=
# Create a reader that will parse slowly (many records)
=
# Flag to track if other thread ran
=
=
"""This thread should be able to run if GIL is released."""
# Wait for main thread to start parsing
# Simply trying to call a Python function should block if GIL not released
# Small sleep to allow main thread to be in Phase 2
# Start background thread
=
# Read records - this should trigger Phase 2 GIL release
= 0
=
+= 1
= -
return 0
return 1