From ff4754c87284ded8c7e4e7e5599df5a77150d8e7 Mon Sep 17 00:00:00 2001 From: Jenn Olsen Date: Wed, 6 Jan 2016 22:40:08 +0000 Subject: [PATCH] release the GIL while compressing and decompressing --- src/python-lz4.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/python-lz4.c b/src/python-lz4.c index 45fe995..9290918 100644 --- a/src/python-lz4.c +++ b/src/python-lz4.c @@ -73,7 +73,10 @@ static PyObject *compress_with(compressor compress, PyObject *self, PyObject *ar dest = PyBytes_AS_STRING(result); store_le32(dest, source_size); if (source_size > 0) { - int osize = compress(source, dest + hdr_size, source_size); + int osize = -1; + Py_BEGIN_ALLOW_THREADS + osize = compress(source, dest + hdr_size, source_size); + Py_END_ALLOW_THREADS int actual_size = hdr_size + osize; /* Resizes are expensive; tolerate some slop to avoid. */ if (actual_size < (dest_size / 4) * 3) { @@ -115,7 +118,10 @@ static PyObject *py_lz4_uncompress(PyObject *self, PyObject *args) { result = PyBytes_FromStringAndSize(NULL, dest_size); if (result != NULL && dest_size > 0) { char *dest = PyBytes_AS_STRING(result); - int osize = LZ4_decompress_safe(source + hdr_size, dest, source_size - hdr_size, dest_size); + int osize = -1; + Py_BEGIN_ALLOW_THREADS + osize = LZ4_decompress_safe(source + hdr_size, dest, source_size - hdr_size, dest_size); + Py_END_ALLOW_THREADS if (osize < 0) { PyErr_Format(PyExc_ValueError, "corrupt input at byte %d", -osize); Py_CLEAR(result);