File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -260,6 +260,14 @@ func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
260260 }
261261 }
262262 }
263+
264+ // release GIL
265+ g .gofile .Printf ("_saved_thread := C.PyEval_SaveThread()\n " )
266+ if ! rvIsErr && nres != 2 {
267+ // reacquire GIL after return
268+ g .gofile .Printf ("defer C.PyEval_RestoreThread(_saved_thread)\n " )
269+ }
270+
263271 if isMethod {
264272 g .gofile .Printf (
265273 `vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "%s")
@@ -407,6 +415,9 @@ if __err != nil {
407415
408416 if rvIsErr || nres == 2 {
409417 g .gofile .Printf ("\n " )
418+ // reacquire GIL
419+ g .gofile .Printf ("C.PyEval_RestoreThread(_saved_thread)\n " )
420+
410421 g .gofile .Printf ("if __err != nil {\n " )
411422 g .gofile .Indent ()
412423 g .gofile .Printf ("estr := C.CString(__err.Error())\n " )
You can’t perform that action at this time.
0 commit comments