From 01f4da08e74b895f8da92373a904d5ef4b9563cd Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Fri, 20 Apr 2018 09:32:11 +0200 Subject: [PATCH] Fix iostream when used with nogil --- include/pybind11/iostream.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h index 182e8eefd8..fe0324cb00 100644 --- a/include/pybind11/iostream.h +++ b/include/pybind11/iostream.h @@ -42,8 +42,11 @@ class pythonbuf : public std::streambuf { // This subtraction cannot be negative, so dropping the sign str line(pbase(), static_cast(pptr() - pbase())); - pywrite(line); - pyflush(); + { + gil_scoped_acquire tmp; + pywrite(line); + pyflush(); + } setp(pbase(), epptr()); }