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

Function PythonReader_Next

plugins/python/redisgears_python.c:6652–6694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6650}PythonReaderCtx;
6651
6652static Record* PythonReader_Next(ExecutionCtx* rctx, void* ctx){
6653 PythonReaderCtx* pyCtx = ctx;
6654 if(pyCtx->isDone){
6655 return NULL;
6656 }
6657
6658 PythonSessionCtx* sctx = RedisGears_GetFlatExecutionPrivateData(rctx);
6659 RedisModule_Assert(sctx);
6660
6661 PythonExecutionCtx pectx = PythonExecutionCtx_New(sctx, rctx);
6662 RedisGearsPy_Lock(&pectx);
6663
6664 PyObject* pyRecord = NULL;
6665 if(!pyCtx->generator){
6666 PyObject* pArgs = PyTuple_New(0);
6667 PyObject* callback = pyCtx->callback;
6668 pyRecord = PyObject_CallObject(callback, pArgs);
6669 GearsPyDecRef(pArgs);
6670 if(!pyRecord){
6671 fetchPyError(rctx);
6672 RedisGearsPy_Unlock(&pectx);
6673 pyCtx->isDone = true;
6674 return NULL;
6675 }
6676 if(PyGen_Check(pyRecord)) {
6677 pyCtx->generator = PyObject_GetIter(pyRecord);
6678 GearsPyDecRef(pyRecord);
6679 pyRecord = PyIter_Next(pyCtx->generator);
6680 }
6681 }else{
6682 pyRecord = PyIter_Next(pyCtx->generator);
6683 }
6684 if(!pyRecord){
6685 fetchPyError(rctx);
6686 RedisGearsPy_Unlock(&pectx);
6687 pyCtx->isDone = true;
6688 return NULL;
6689 }
6690 RedisGearsPy_Unlock(&pectx);
6691 Record* record = PyObjRecordCreate();
6692 PyObjRecordSet(record, pyRecord);
6693 return record;
6694}
6695
6696static void PythonReader_Free(void* ctx){
6697 PythonReaderCtx* pyCtx = ctx;

Callers

nothing calls this directly

Calls 6

RedisGearsPy_LockFunction · 0.85
GearsPyDecRefFunction · 0.85
fetchPyErrorFunction · 0.85
RedisGearsPy_UnlockFunction · 0.85
PyObjRecordCreateFunction · 0.85
PyObjRecordSetFunction · 0.85

Tested by

no test coverage detected