From 961b2e6205647f0308b2e9fb13d884c18fcb23ef Mon Sep 17 00:00:00 2001 From: Hyrum Wright Date: Fri, 2 Oct 2020 17:00:45 -0400 Subject: [PATCH] fix: ensure the GIL is held when copying a function. (#2545) Co-authored-by: Hyrum Wright --- include/pybind11/functional.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 57b6cd210..92c17dc22 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -58,7 +58,10 @@ public: struct func_handle { function f; func_handle(function&& f_) : f(std::move(f_)) {} - func_handle(const func_handle&) = default; + func_handle(const func_handle& f_) { + gil_scoped_acquire acq; + f = f_.f; + } ~func_handle() { gil_scoped_acquire acq; function kill_f(std::move(f));