MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / gearsCtx

Function gearsCtx

plugins/python/redisgears_python.c:2996–3046  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2994}
2995
2996static PyObject* gearsCtx(PyObject *cls, PyObject *args){
2997 PythonThreadCtx* ptctx = GetPythonThreadCtx();
2998 if(!ptctx->currSession){
2999 PyErr_SetString(GearsError, "Can not create a gearsCtx on a python created thread");
3000 return NULL;
3001 }
3002 const char* readerStr = "KeysReader";
3003 const char* descStr = NULL;
3004 if(PyTuple_Size(args) > 0){
3005 PyObject* reader = PyTuple_GetItem(args, 0);
3006 if(!PyUnicode_Check(reader)){
3007 PyErr_SetString(GearsError, "reader argument must be a string");
3008 return NULL;
3009 }
3010 readerStr = PyUnicode_AsUTF8AndSize(reader, NULL);
3011 }
3012 if(PyTuple_Size(args) > 1){
3013 PyObject* desc = PyTuple_GetItem(args, 1);
3014 if(desc != Py_None && !PyUnicode_Check(desc)){
3015 PyErr_SetString(GearsError, "desc argument must be a string");
3016 return NULL;
3017 }
3018 if(desc != Py_None){
3019 descStr = PyUnicode_AsUTF8AndSize(desc, NULL);
3020 }
3021 }
3022 PyFlatExecution* pyfep = PyObject_New(PyFlatExecution, &PyFlatExecutionType);
3023 char* err = NULL;
3024 pyfep->fep = RedisGears_CreateCtx((char*)readerStr, &err);
3025 if(!pyfep->fep){
3026 Py_DecRef((PyObject*)pyfep);
3027 if(!err){
3028 err = RG_STRDUP("the given reader are not exists");
3029 }
3030 PyErr_SetString(GearsError, err);
3031 RG_FREE(err);
3032 return NULL;
3033 }
3034 if(descStr){
3035 RedisGears_SetDesc(pyfep->fep, descStr);
3036 }
3037 RGM_Map(pyfep->fep, RedisGearsPy_ToPyRecordMapper, NULL);
3038 RedisGears_SetFlatExecutionPrivateData(pyfep->fep, "PySessionType", PythonSessionCtx_ShallowCopy(ptctx->currSession));
3039
3040 if(RGM_SetFlatExecutionOnUnpausedCallback(pyfep->fep, RedisGearsPy_OnExecutionUnpausedCallback, NULL) != REDISMODULE_OK){
3041 GearsPyDecRef((PyObject*)pyfep);
3042 PyErr_SetString(GearsError, "Failed setting on unpause callback");
3043 return NULL;
3044 }
3045 return (PyObject*)pyfep;
3046}
3047
3048static PyObject* saveGlobals(PyObject *cls, PyObject *args){
3049 pyGlobals = PyEval_GetGlobals();

Callers 1

__init__Method · 0.90

Calls 3

GetPythonThreadCtxFunction · 0.85
GearsPyDecRefFunction · 0.85

Tested by

no test coverage detected