I have some C++ code which is calling a function inside a python file. If I try to read a pickled file in the python code then I get the following error:
Exception ignored in: <module 'threading' from 'C:\\Anaconda3\\envs\\Deep_Learning\\lib\\threading.py'>
Traceback (most recent call last):
File "C:\Anaconda3\envs\Deep_Learning\lib\threading.py", line 1289, in _shutdown
assert tlock.locked()
SystemError: <built-in method locked of _thread.lock object at 0x000002328D1EAAA8> returned a result with an error set
Python file:
def test():
print("In function test of pyemb.py file \n")
import pickle
with open('filepath', 'rb') as f_in:
C = pickle.load(f_in)
C++ (This file is calling the python file)
#include <stdio.h>
#include <conio.h>
#include <pyhelper.hpp>
#include <iostream>
int main()
{
CPyInstance hInstance;
CPyObject pName = PyUnicode_FromString("pyemb");
CPyObject pModule = PyImport_Import(pName); //importing the file
if (pModule)
{
std::cout << "Module load successful" << std::endl;
CPyObject pFunc1 = PyObject_GetAttrString(pModule, "test"); //passing name of function to be called
if (pFunc1 && PyCallable_Check(pFunc1)) // checking if not null and callable
{
PyObject_CallObject(pFunc1, NULL);
}
else
{
printf("ERROR: function test didn't run as intended\n");
}
}
else
{
printf_s("ERROR: Module not imported\n");
}
return 0;
}
C++(pyhelper.hpp to handle Py_Initialize ,Py_Finalize etc)
#ifndef PYHELPER_HPP
#define PYHELPER_HPP
#pragma once
#include <Python.h>
// This will take care of closing the session when CPyInstance scope ends,
// as destructor will be implicitly called to close the Py instance
class CPyInstance
{
public:
CPyInstance()
{
// Setting Python home path for reading lib and bin
Py_SetPythonHome(const_cast<wchar_t*>(L"C:\\Anaconda3\\envs\\Deep_Learning"));
// Initializing Python interpreter
Py_Initialize();
// Setting path for python to find our python model files
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\"C:\\python_files\")");
}
~CPyInstance()
{
Py_Finalize(); // closes the python interpreter instance
}
};
...More code for other stuff...
How can I fix this?
Please help.