Skip to content

Commit 3b6fc61

Browse files
authored
Merge pull request #285 from feast-dev/release-gil
Release GIL in function generator
2 parents d1cbf66 + d8c8eee commit 3b6fc61

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

bind/gen_func.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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")

0 commit comments

Comments
 (0)