tuplex/python/src/PythonContext.cc
// // running with another python version might lead to severe issues
// // hence, perform check at context startup!
// bool checkPythonVersion() {
//    using namespace std;
//    cout<<"PYTHON ABI: "<<PYTHON_ABI_STRING<<endl;
//    cout<<"Compiled Python version: "<<PY_MAJOR_VERSION<<"."<<PY_MINOR_VERSION<<"."<<PY_MICRO_VERSION<<endl;
//    cout<<"Retrieved Python version: "<<Py_GetVersion()<<endl;
//    cout<<"Python home: "<<Py_GetPythonHome()<<endl;
//    return true;
// }
running with another python version might lead to severe issues
hence, perform check at context startup.
running with another python version might lead to severe issues hence perform check at context startup .
PythonContext::PythonContext(const std::string& name,
                                 const std::string &runtimeLibraryPath,
                                 const std::string& options) {
        using namespace std;
        ContextOptions co = ContextOptions::defaults();
#warning "this code is commented, because it will cause a deadlock sometimes... Uncomment to activate output in Jupyter notebook."
        if(runtimeLibraryPath.length() > 0)
            co.set("tuplex.runTimeLibrary", runtimeLibraryPath);
         co = updateOptionsWithDict(co, options);
        python::unlockGIL();
        auto uri = co.RUNTIME_LIBRARY(true);
        python::lockGIL();
        if(uri == URI::INVALID) {
            throw PythonException("Could not find runtime library under " + co.get("tuplex.runTimeLibrary"));
        }
        Logger::instance().defaultLogger().debug("Using runtime library from  " + uri.toPath());
        co.set("tuplex.runTimeLibrary", uri.toPath());
        assert(PyGILState_Check()); 
        python::unlockGIL();
        std::string err_message = ""; 
        try {
            _context = new Context(co);
            if(!name.empty())
                _context->setName(name);
        } catch(const std::exception& e) {
            err_message = e.what();
            assert(!err_message.empty());
            Logger::instance().defaultLogger().error(err_message);
        } catch(...) {
            err_message = "unknown C++ exception occurred, please change type s.t. it's derived from std::exception for meaningful display.";
            Logger::instance().defaultLogger().error(err_message);
        }
        python::lockGIL();
        Logger::instance().flushAll();
        if(!err_message.empty()) {
            PyErr_SetString(PyExc_RuntimeError, err_message.c_str());
        }
    }
PythonContext :: PythonContext ( const std :: string & name , const std :: string & runtimeLibraryPath , const std :: string & options ) { using namespace std ; ContextOptions co = ContextOptions :: defaults ( ) ; #warning  "this code is commented, because it will cause a deadlock sometimes... Uncomment to activate output in Jupyter notebook." if ( runtimeLibraryPath . length ( ) > 0 ) co . set ( " " , runtimeLibraryPath ) ; co = updateOptionsWithDict ( co , options ) ; python :: unlockGIL ( ) ; auto uri = co . RUNTIME_LIBRARY ( true ) ; python :: lockGIL ( ) ; if ( uri == URI :: INVALID ) { throw PythonException ( " " + co . get ( " " ) ) ; } Logger :: instance ( ) . defaultLogger ( ) . debug ( " " + uri . toPath ( ) ) ; co . set ( " " , uri . toPath ( ) ) ; assert ( PyGILState_Check ( ) ) ; python :: unlockGIL ( ) ; std :: string err_message = " " ; try { _context = new Context ( co ) ; if ( ! name . empty ( ) ) _context -> setName ( name ) ; } catch ( const std :: exception & e ) { err_message = e . what ( ) ; assert ( ! err_message . empty ( ) ) ; Logger :: instance ( ) . defaultLogger ( ) . error ( err_message ) ; } catch ( ... ) { err_message = " " ; Logger :: instance ( ) . defaultLogger ( ) . error ( err_message ) ; } python :: lockGIL ( ) ; Logger :: instance ( ) . flushAll ( ) ; if ( ! err_message . empty ( ) ) { PyErr_SetString ( PyExc_RuntimeError , err_message . c_str ( ) ) ; } }
running with another python version might lead to severe issues
 hence, perform check at context startup!
running with another python version might lead to severe issues hence perform check at context startup!
// checkPythonVersion(); // init logging system here // @TODO: add as context option // note: this should come BEFORE any Logger::instance()... calls //Logger::init({std::make_shared<python3_sink_mt>()}); //#ifndef NDEBUG //        // print settings //        Logger::instance().defaultLogger().info("Tuplex configuration:"); //        auto store = co.store(); //        for(auto keyval : store) { //            Logger::instance().defaultLogger().info(keyval.first + "=" + keyval.second); //        } //#endif // testwise retrieve runtime path. This may be a critical error, hence throw PyException! // store explicitly uri in context options so no searching happens anymore // for context creation release GIL // make sure this thread holds the GIL! // leave this as empty string! // restore GIL // manually set python error -> do not trust boost::python exception translation, it's faulty!