Skip to content

Commit 22450e3

Browse files
committed
del sid when once
1 parent 2dea7a0 commit 22450e3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pyWrapper.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,11 @@ int PyWrapper::wrapperFini() {
241241

242242
int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::string> params, DataListCls reqData,
243243
pDataList *respData, std::string sid, wrapperCallback cb) {
244+
SetSidUsrTag(sid, usrTag);
244245
try {
245246
if (cb != nullptr) {
246247
SetSidCallBack(cb, sid);
247-
248248
}
249-
SetSidUsrTag(sid, usrTag);
250249
params["sid"] = sid;
251250
// 执行python exec 推理
252251
py::object r = _wrapperOnceExec(params, reqData, usrTag);
@@ -260,12 +259,14 @@ int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::s
260259
// 先判断python有没有抛出错误. response中的 errorCode
261260
if (resp->errCode != 0) {
262261
spdlog::error("find error from python: {}", resp->errCode);
262+
DelSidUsrTag(sid);
263263
return resp->errCode;
264264
}
265265

266266
int dataSize = resp->list.size();
267267
if (dataSize == 0) {
268268
spdlog::error("error, not find any data from resp");
269+
DelSidUsrTag(sid);
269270
return -1;
270271
}
271272
for (int idx = 0; idx < dataSize; idx++) {
@@ -283,6 +284,7 @@ int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::s
283284
if (pr == nullptr) {
284285
int ret = -1;
285286
spdlog::error("can't malloc memory for data, sid:{}", sid);
287+
DelSidUsrTag(sid);
286288
return ret;
287289
}
288290
ptr = PyBytes_AsString(itemData.data.ptr());
@@ -309,17 +311,22 @@ int PyWrapper::wrapperOnceExec(const char *usrTag, std::map <std::string, std::s
309311
}
310312
catch (py::cast_error &e) {
311313
spdlog::error("cast error: {}", e.what());
314+
DelSidUsrTag(sid);
312315
return -1;
313316
}
314317
catch (py::error_already_set &e) {
315318
spdlog::error("error_already_set error: {}", e.what());
319+
DelSidUsrTag(sid);
320+
316321
return -1;
317322
}
318323
catch (const std::exception &e) {
319324
spdlog::error("error_already_set error: {}", e.what());
325+
DelSidUsrTag(sid);
326+
320327
return -1;
321328
}
322-
329+
DelSidUsrTag(sid);
323330
return 0;
324331

325332
}

0 commit comments

Comments
 (0)