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

Function PythonSessionCtx_CreateWithId

plugins/python/redisgears_python.c:813–873  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

811}
812
813static PythonSessionCtx* PythonSessionCtx_CreateWithId(const char* id, const char* desc, const char** requirementsList, size_t requirementsListLen, bool forceReqReinstallation){
814 // creating a new global dict for this session
815 RedisGearsPy_LOCK
816
817 PyObject* globalDict = PyDict_Copy(pyGlobals);
818
819 PythonSessionCtx* session = RG_ALLOC(sizeof(*session));
820 *session = (PythonSessionCtx){
821 .sessionId = RG_STRDUP(id),
822 .sessionDesc = desc? RG_STRDUP(desc) : NULL,
823 .refCount = 1,
824 .globalsDict = globalDict,
825 .isInstallationNeeded = false,
826 .profiler = PyObject_CallFunction(profileCreateFunction, NULL),
827 .registrations = array_new(char*, 10),
828 .srctx = NULL,
829 .linkedTo = LinkedTo_None,
830 .deadNode = NULL,
831 .fullSerialization = false,
832
833 };
834 pthread_mutex_init(&session->registrationsLock, NULL);
835
836 session->requirements = array_new(PythonRequirementCtx*, 10);
837
838 if (!forceReqReinstallation) {
839 // lets see if we already have the requirements installed
840 for(size_t i = 0 ; i < requirementsListLen ; ++i){
841 PythonRequirementCtx *req = PythonRequirementCtx_Get(requirementsList[i]);
842 if (!req) {
843 session->isInstallationNeeded = true;
844 break;
845 } else {
846 session->requirements = array_append(session->requirements , req);
847 }
848 }
849 } else {
850 session->isInstallationNeeded = true;
851 }
852
853 if (session->isInstallationNeeded) {
854 while(array_len(session->requirements) > 0) {
855 PythonRequirementCtx *req = array_pop(session->requirements);
856 PythonRequirementCtx_Free(req);
857 }
858 for(size_t i = 0 ; i < requirementsListLen ; ++i){
859 PythonRequirementCtx* req = PythonRequirementCtx_Create(requirementsList[i]);
860
861 if(!req){
862 PythonSessionCtx_Free(session);
863 session = NULL;
864 break;
865 }
866 session->requirements = array_append(session->requirements , req);
867 }
868 }
869
870 RedisGearsPy_UNLOCK

Callers 2

PythonSessionCtx_CreateFunction · 0.85

Calls 5

PythonRequirementCtx_GetFunction · 0.85
array_lenFunction · 0.85
PythonSessionCtx_FreeFunction · 0.85

Tested by

no test coverage detected