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()); }