Example #1
0
func pickleInit() {
	C.Py_Initialize()
	var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
	pickleLoads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
	pickleDumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
	highestProtocol = C.PyObject_GetAttrString(cPickle, C.CString("HIGHEST_PROTOCOL"))
	C.Py_DecRef(cPickle)
	initialized = 1
}
Example #2
0
func _pickle_init() {
	if initialized == 0 {
		C.Py_Initialize()
		var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
		pickle_loads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
		pickle_dumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
		C.Py_DecRef(cPickle)
		initialized = 1
	}
}
Example #3
0
// Initialize initializes the python interpreter and its GIL
func Initialize() error {
	// make sure the python interpreter has been initialized
	if C.Py_IsInitialized() == 0 {
		C.Py_Initialize()
	}
	if C.Py_IsInitialized() == 0 {
		return fmt.Errorf("python: could not initialize the python interpreter")
	}

	// make sure the GIL is correctly initialized
	if C.PyEval_ThreadsInitialized() == 0 {
		C.PyEval_InitThreads()
	}
	if C.PyEval_ThreadsInitialized() == 0 {
		return fmt.Errorf("python: could not initialize the GIL")
	}

	return nil
}
func init() {
	log.Debug("> Initilize Python.")

	runtime.LockOSThread()

	if C.Py_IsInitialized() == 0 {
		C.Py_Initialize()
	}
	if C.Py_IsInitialized() == 0 {
		panic(fmt.Errorf("python: could not initialize the python interpreter"))
	}

	// make sure the GIL is correctly initialized
	if C.PyEval_ThreadsInitialized() == 0 {
		C.PyEval_InitThreads()
	}
	if C.PyEval_ThreadsInitialized() == 0 {
		panic(fmt.Errorf("python: could not initialize the GIL"))
	}
	log.Debug("< Initilized Python.")
	_tstate := C.PyGILState_GetThisThreadState()
	C.PyEval_ReleaseThread(_tstate)
}
Example #5
0
func Initialize() {
	C.Py_Initialize()
}
Example #6
0
func init() {
	C.Py_Initialize()
}