Skip to content

Commit 8383350

Browse files
committed
Merge pull request axiak#22 from socketpair/release_gil_on_compile
Release GIL during regex compilation.
2 parents a83f775 + 8b8f637 commit 8383350

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/_re2.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ cdef extern from "re2/re2.h" namespace "re2":
9494
ctypedef Options const_Options "const RE2::Options"
9595

9696
cdef cppclass RE2:
97-
RE2(const_StringPiece pattern, Options option)
98-
RE2(const_StringPiece pattern)
97+
RE2(const_StringPiece pattern, Options option) nogil
98+
RE2(const_StringPiece pattern) nogil
9999
int Match(const_StringPiece text, int startpos, int endpos,
100100
Anchor anchor, StringPiece * match, int nmatch) nogil
101101
int NumberOfCapturingGroups()

src/re2.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,9 @@ def _compile(pattern, int flags=0, int max_mem=8388608):
953953

954954
s = new _re2.StringPiece(string, length)
955955

956-
cdef _re2.RE2 * re_pattern = new _re2.RE2(s[0], opts)
956+
cdef _re2.RE2 *re_pattern
957+
with nogil:
958+
re_pattern = new _re2.RE2(s[0], opts)
957959

958960
if not re_pattern.ok():
959961
# Something went wrong with the compilation.

0 commit comments

Comments
 (0)