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
Xavier Thompson
cython
Commits
5dc832d3
Commit
5dc832d3
authored
Feb 25, 2019
by
Noam Hershtig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add conditional GILStatNode usage to documentation
parent
f8e58c5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
docs/src/userguide/external_C_code.rst
docs/src/userguide/external_C_code.rst
+20
-0
docs/src/userguide/fusedtypes.rst
docs/src/userguide/fusedtypes.rst
+28
-0
No files found.
docs/src/userguide/external_C_code.rst
View file @
5dc832d3
...
...
@@ -580,6 +580,26 @@ The GIL may also be acquired through the ``with gil`` statement::
with gil:
<execute this block with the GIL acquired>
.. _gil_conditional:
Conditional Acquiring / Releasing the GIL
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sometimes it is helpful to use a condition to decide whether to run a
certain piece of code with or without the GIL. This code would run anyway,
the difference is whether the GIL will be held or released.
The condition must be constant (at compile time).
This could be useful for profiling, debugging, performance testing, and
for fused types (see :ref:`fused_gil_conditional`).::
DEF FREE_GIL = True
with nogil(FREE_GIL):
<code to be executed with the GIL released>
with gil(False):
<GIL is still released>
Declaring a function as callable without the GIL
--------------------------------------------------
...
...
docs/src/userguide/fusedtypes.rst
View file @
5dc832d3
...
...
@@ -249,6 +249,34 @@ to figure out whether a specialization is part of another set of types
if bunch_of_types in string_t:
print("s is a string!")
.. _fused_gil_conditional:
Conditional GIL Acquiring / Releasing
=====================================
Acquiring and releasing the GIL can be controlled by a condition
which is known at compile time (see :ref:`_gil_conditional`).
This is most useful when combined with fused types.
A fused type function may have to handle both cython native types
(e.g. cython.int or cython.double) and python types (e.g. object or bytes).
Conditional Acquiring / Releasing the GIL provides a method for running
the same piece of code either with the GIL released (for cython native types)
and with the GIL held (for python types).::
cimport cython
ctypedef fused double_or_object:
cython.double
object
def increment(double_or_object x):
with nogil(double_or_object is cython.double):
# Same code handles both cython.double (GIL is released)
# and python object (GIL is not released).
x = x + 1
return x
__signatures__
==============
...
...
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