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
d93be9df
Commit
d93be9df
authored
Feb 04, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow nogil try/finally without 'with gil' block
parent
f0cfc682
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
16 deletions
+20
-16
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-15
tests/errors/nogil.pyx
tests/errors/nogil.pyx
+0
-1
tests/run/with_gil.pyx
tests/run/with_gil.pyx
+18
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
d93be9df
...
...
@@ -2281,9 +2281,6 @@ class GilCheck(VisitorTransform):
# which is wrapped in a StatListNode. Just unpack that.
node
.
finally_clause
,
=
node
.
finally_clause
.
stats
if
node
.
state
==
'gil'
:
self
.
seen_with_gil_statement
=
True
self
.
visitchildren
(
node
)
self
.
nogil
=
was_nogil
return
node
...
...
@@ -2319,24 +2316,14 @@ class GilCheck(VisitorTransform):
def
visit_TryFinallyStatNode
(
self
,
node
):
"""
Take care of try/finally statements in nogil code sections. The
'try' must contain a 'with gil:' statement somewhere.
Take care of try/finally statements in nogil code sections.
"""
if
not
self
.
nogil
or
isinstance
(
node
,
Nodes
.
GILStatNode
):
return
self
.
visit_Node
(
node
)
node
.
nogil_check
=
None
node
.
is_try_finally_in_nogil
=
True
# First, visit the body and check for errors
self
.
seen_with_gil_statement
=
False
self
.
visitchildren
(
node
.
body
)
if
not
self
.
seen_with_gil_statement
:
error
(
node
.
pos
,
"Cannot use try/finally in nogil sections unless "
"it contains a 'with gil' statement."
)
self
.
visitchildren
(
node
.
finally_clause
)
self
.
visitchildren
(
node
)
return
node
def
visit_Node
(
self
,
node
):
...
...
tests/errors/nogil.pyx
View file @
d93be9df
...
...
@@ -159,6 +159,5 @@ _ERRORS = u"""
62:14: Coercion from Python not allowed without the GIL
62:25: Coercion from Python not allowed without the GIL
64:8: Try-except statement not allowed without gil
68:8: Cannot use try/finally in nogil sections unless it contains a 'with gil' statement.
85:8: For-loop using object bounds or target not allowed without gil
"""
tests/run/with_gil.pyx
View file @
d93be9df
...
...
@@ -438,3 +438,21 @@ def test_nogil_try_finally_return():
"""
with
nogil
:
nogil_try_finally_return
()
cdef
int
error_func
()
except
-
1
with
gil
:
raise
Exception
(
"propagate this"
)
def
test_nogil_try_finally_error_label
():
"""
>>> test_nogil_try_finally_error_label()
print me first
propagate this
"""
try
:
with
nogil
:
try
:
error_func
()
finally
:
with
gil
:
print
"print me first"
except
Exception
,
e
:
print
e
.
args
[
0
]
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