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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
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
Hide 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):
...
@@ -2281,9 +2281,6 @@ class GilCheck(VisitorTransform):
# which is wrapped in a StatListNode. Just unpack that.
# which is wrapped in a StatListNode. Just unpack that.
node
.
finally_clause
,
=
node
.
finally_clause
.
stats
node
.
finally_clause
,
=
node
.
finally_clause
.
stats
if
node
.
state
==
'gil'
:
self
.
seen_with_gil_statement
=
True
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
self
.
nogil
=
was_nogil
self
.
nogil
=
was_nogil
return
node
return
node
...
@@ -2319,24 +2316,14 @@ class GilCheck(VisitorTransform):
...
@@ -2319,24 +2316,14 @@ class GilCheck(VisitorTransform):
def
visit_TryFinallyStatNode
(
self
,
node
):
def
visit_TryFinallyStatNode
(
self
,
node
):
"""
"""
Take care of try/finally statements in nogil code sections. The
Take care of try/finally statements in nogil code sections.
'try' must contain a 'with gil:' statement somewhere.
"""
"""
if
not
self
.
nogil
or
isinstance
(
node
,
Nodes
.
GILStatNode
):
if
not
self
.
nogil
or
isinstance
(
node
,
Nodes
.
GILStatNode
):
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
node
.
nogil_check
=
None
node
.
nogil_check
=
None
node
.
is_try_finally_in_nogil
=
True
node
.
is_try_finally_in_nogil
=
True
self
.
visitchildren
(
node
)
# 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
)
return
node
return
node
def
visit_Node
(
self
,
node
):
def
visit_Node
(
self
,
node
):
...
...
tests/errors/nogil.pyx
View file @
d93be9df
...
@@ -159,6 +159,5 @@ _ERRORS = u"""
...
@@ -159,6 +159,5 @@ _ERRORS = u"""
62:14: Coercion from Python not allowed without the GIL
62:14: Coercion from Python not allowed without the GIL
62:25: 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
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
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():
...
@@ -438,3 +438,21 @@ def test_nogil_try_finally_return():
"""
"""
with
nogil
:
with
nogil
:
nogil_try_finally_return
()
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