func initAndLock(initsigs bool) *Lock { // Lock the current goroutine to the current OS thread, until we have // released the GIL (as CPython uses per-thread state) runtime.LockOSThread() // Initialize the default Python interpreter if initsigs { C.Py_InitializeEx(1) } else { C.Py_InitializeEx(0) } // Enable Python thread support, and then immediately release the GIL (and // thus "deativate" and per-thread state associated with the current thread C.PyEval_InitThreads() C.PyEval_SaveThread() // We can now unlock the current goroutine from the current OS thread, as // there is no active per-thread state runtime.UnlockOSThread() // Now that Python is setup, we can return a locked Lock, ready for the // calling code to use return NewLock() }
func InitializeEx(initsigs bool) { if initsigs { C.Py_InitializeEx(1) } else { C.Py_InitializeEx(0) } }
func InitializeEx(initsigs bool) { if initsigs { panic("Python signal handlers can not be enabled. See https://code.google.com/p/go/issues/detail?id=5287 for details") } else { C.Py_InitializeEx(0) } }
func threadInit() (defaultThreadState *C.PyThreadState) { initLock.Lock() defer initLock.Unlock() if !initialized { C.Py_InitializeEx(0) C.PyEval_InitThreads() C.PySys_SetArgvEx(0, nil, 0) pyEmptyTuple = C.PyTuple_New(0) falseObject = &object{C.False_INCREF()} trueObject = &object{C.True_INCREF()} defaultThreadState = C.PyEval_SaveThread() initialized = true } return }