From 09f7cd0d0814bc6bfb50e966eed1946072cccf20 Mon Sep 17 00:00:00 2001 From: Mike Laiosa Date: Sun, 15 Oct 2023 23:33:44 -0700 Subject: [PATCH] Unlock the GIL for all capnp functions that do IO IO might block, and its rude to block while holding the GIL, since that prevents other threads from running. --- capnp/lib/capnp.pyx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 554144a..499e175 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -3739,7 +3739,9 @@ cdef class _StreamFdMessageReader(_MessageReader): cdef schema_cpp.ReaderOptions opts = make_reader_opts(traversal_limit_in_words, nesting_limit) self._parent = file - self.thisptr = new schema_cpp.StreamFdMessageReader(file.fileno(), opts) + cdef int fd = file.fileno() + with nogil: + self.thisptr = new schema_cpp.StreamFdMessageReader(fd, opts) def __dealloc__(self): del self.thisptr @@ -3842,7 +3844,9 @@ cdef class _PackedFdMessageReader(_MessageReader): cdef schema_cpp.ReaderOptions opts = make_reader_opts(traversal_limit_in_words, nesting_limit) self._parent = file - self.thisptr = new schema_cpp.PackedFdMessageReader(file.fileno(), opts) + cdef int fd = file.fileno() + with nogil: + self.thisptr = new schema_cpp.PackedFdMessageReader(fd, opts) def __dealloc__(self): del self.thisptr @@ -4251,7 +4255,8 @@ def _write_message_to_fd(int fd, _MessageBuilder message): :rtype: void """ - schema_cpp.writeMessageToFd(fd, deref(message.thisptr)) + with nogil: + schema_cpp.writeMessageToFd(fd, deref(message.thisptr)) def _write_packed_message_to_fd(int fd, _MessageBuilder message): @@ -4278,7 +4283,8 @@ def _write_packed_message_to_fd(int fd, _MessageBuilder message): :rtype: void """ - schema_cpp.writePackedMessageToFd(fd, deref(message.thisptr)) + with nogil: + schema_cpp.writePackedMessageToFd(fd, deref(message.thisptr)) _global_schema_parser = None