summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2013-04-28 11:35:33 +0200
committerStefan Behnel <stefan_ml@behnel.de>2013-04-28 11:35:33 +0200
commit3256ccb8eec06e782fdcc6f39e49dfa4c7896a17 (patch)
treec52a044006df8bb664cb37b81d401f75ebb3ffcd
parent1d4ecb12d5bd2858a1ab5c29f9401518b7f87647 (diff)
downloadpython-lxml-3256ccb8eec06e782fdcc6f39e49dfa4c7896a17.tar.gz
free GIL in resolver code when libxml2 potentially does I/O
-rw-r--r--src/lxml/parser.pxi18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi
index 644d42a4..d8903d1b 100644
--- a/src/lxml/parser.pxi
+++ b/src/lxml/parser.pxi
@@ -427,7 +427,10 @@ cdef xmlparser.xmlParserInput* _local_resolver(const_char* c_url, const_char* c_
if context is None:
if __DEFAULT_ENTITY_LOADER is NULL:
return NULL
- return __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
+ with nogil:
+ # free the GIL as we might do serious I/O here (e.g. HTTP)
+ c_input = __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
+ return c_input
try:
if c_url is NULL:
@@ -456,8 +459,11 @@ cdef xmlparser.xmlParserInput* _local_resolver(const_char* c_url, const_char* c_
c_input.end = c_input.base + c_input.length
elif doc_ref._type == PARSER_DATA_FILENAME:
data = None
- c_input = xmlparser.xmlNewInputFromFile(
- c_context, _cstr(doc_ref._filename))
+ c_filename = _cstr(doc_ref._filename)
+ with nogil:
+ # free the GIL as we might do serious I/O here
+ c_input = xmlparser.xmlNewInputFromFile(
+ c_context, c_filename)
elif doc_ref._type == PARSER_DATA_FILE:
file_context = _FileReaderContext(doc_ref._file, context, url,
None, doc_ref._close_file)
@@ -474,7 +480,11 @@ cdef xmlparser.xmlParserInput* _local_resolver(const_char* c_url, const_char* c_
if __DEFAULT_ENTITY_LOADER is NULL:
return NULL
- return __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
+
+ with nogil:
+ # free the GIL as we might do serious I/O here (e.g. HTTP)
+ c_input = __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
+ return c_input
cdef xmlparser.xmlExternalEntityLoader __DEFAULT_ENTITY_LOADER
__DEFAULT_ENTITY_LOADER = xmlparser.xmlGetExternalEntityLoader()