Commit 96907e3
committed
Add GILGuard::check() for python3
Adds a function that returns true if the GIL is currently held for the
current thread. PyGILState_Check() was only added in Python 3.4, so this
doesn't support Python 2.7.
When working with py.allow_threads(...) it is useful for the inner code
to be able to verify the GIL is not held in case it needs to acquire the
GIL on other threads. Being able to check this can help prevent
accidental deadlocks.
Ideally this could be done via static typing, similar to how the 'py'
object ensures the GIL is held, but I couldn't think of a clever way to
achieve this.1 parent 8d94120 commit 96907e3
File tree
3 files changed
+11
-2
lines changed- python27-sys/src
- python3-sys/src
- src
3 files changed
+11
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
131 | 138 | | |
132 | 139 | | |
133 | 140 | | |
| |||
0 commit comments