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
01085d2a
Commit
01085d2a
authored
Apr 28, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the GIL-avoidance in
7d99b0f0
actually work in nogil functions and not just nogil sections.
Closes #3558.
parent
7f5956f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
6 deletions
+34
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+4
-2
tests/run/with_gil_automatic.pyx
tests/run/with_gil_automatic.pyx
+30
-4
No files found.
Cython/Compiler/Nodes.py
View file @
01085d2a
...
...
@@ -1847,10 +1847,12 @@ class FuncDefNode(StatNode, BlockNode):
use_refnanny
=
not
lenv
.
nogil
or
lenv
.
has_with_gil_block
gilstate_decl
=
code
.
insertion_point
()
gilstate_decl
=
None
if
acquire_gil
or
acquire_gil_for_var_decls_only
:
code
.
put_ensure_gil
()
code
.
funcstate
.
gil_owned
=
True
else
:
gilstate_decl
=
code
.
insertion_point
()
if
profile
or
linetrace
:
if
not
self
.
is_generator
:
...
...
@@ -1976,7 +1978,7 @@ class FuncDefNode(StatNode, BlockNode):
gil_owned
=
{
'success'
:
code
.
funcstate
.
gil_owned
,
'error'
:
code
.
funcstate
.
gil_owned
,
'gil_state_declared'
:
Fals
e
,
'gil_state_declared'
:
gilstate_decl
is
Non
e
,
}
def
assure_gil
(
code_path
):
if
not
gil_owned
[
code_path
]:
...
...
tests/run/with_gil_automatic.pyx
View file @
01085d2a
...
...
@@ -10,26 +10,52 @@ cimport cython
"//GILStatNode//GILStatNode"
,
"//GILStatNode//GILStatNode//PrintStatNode"
,
)
def
test_print_in_nogil
(
x
):
def
test_print_in_nogil
_section
(
x
):
"""
>>> test_print_in_nogil(123)
>>> test_print_in_nogil
_section
(123)
--123--
"""
with
nogil
:
print
f"--
{
x
}
--"
@
cython
.
test_assert_path_exists
(
"//GILStatNode"
,
"//GILStatNode//PrintStatNode"
,
)
cpdef
int
test_print_in_nogil_func
(
x
)
nogil
except
-
1
:
"""
>>> _ = test_print_in_nogil_func(123)
--123--
"""
print
f"--
{
x
}
--"
@
cython
.
test_assert_path_exists
(
"//GILStatNode"
,
"//GILStatNode//GILStatNode"
,
"//GILStatNode//GILStatNode//RaiseStatNode"
,
)
def
test_raise_in_nogil
(
x
):
def
test_raise_in_nogil
_section
(
x
):
"""
>>> try: test_raise_in_nogil(123)
>>> try: test_raise_in_nogil
_section
(123)
... except ValueError as exc: print(exc)
... else: print("NOT RAISED !")
--123--
"""
with
nogil
:
raise
ValueError
(
f"--
{
x
}
--"
)
@
cython
.
test_assert_path_exists
(
"//GILStatNode"
,
"//GILStatNode//RaiseStatNode"
,
)
cpdef
int
test_raise_in_nogil_func
(
x
)
nogil
except
-
1
:
"""
>>> try: test_raise_in_nogil_func(123)
... except ValueError as exc: print(exc)
... else: print("NOT RAISED !")
--123--
"""
raise
ValueError
(
f"--
{
x
}
--"
)
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