Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
0ed163b3
Commit
0ed163b3
authored
Feb 24, 2022
by
Matus Valo
Committed by
GitHub
Feb 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: Explain GIL handling in pure.rst (#4650)
parent
c7792c1f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+40
-0
No files found.
docs/src/tutorial/pure.rst
View file @
0ed163b3
...
...
@@ -209,6 +209,46 @@ Here is an example of a :keyword:`cdef` function::
return a == b
Managing the Global Interpreter Lock
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* ``cython.nogil`` can be used as a context manager or as a decorator to replace the :keyword:`nogil` keyword::
with cython.nogil:
# code block with the GIL released
@cython.nogil
@cython.cfunc
def func_released_gil() -> cython.int:
# function with the GIL released
* ``cython.gil`` can be used as a context manager to replace the :keyword:`gil` keyword::
with cython.gil:
# code block with the GIL acquired
.. Note:: Cython currently does not support the ``@cython.with_gil`` decorator.
Both directives accept an optional boolean parameter for conditionally
releasing or acquiring the GIL. The condition must be constant (at compile time)::
with cython.nogil(False):
# code block with the GIL not released
@cython.nogil(True)
@cython.cfunc
def func_released_gil() -> cython.int:
# function with the GIL released
with cython.gil(False):
# code block with the GIL not acquired
with cython.gil(True):
# code block with the GIL acquired
A common use case for conditionally acquiring and releasing the GIL are fused types
that allow different GIL handling depending on the specific type (see :ref:`gil_conditional`).
cimports
^^^^^^^^
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment