@@ -1215,7 +1215,13 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
1215
1215
PyObject * eo , * result ;
1216
1216
CallState * cs ;
1217
1217
1218
- cs = CallState_get (h );
1218
+ /* Avoid grabbing the GIL if it's not needed */
1219
+ if (!h -> error_cb && err != RD_KAFKA_RESP_ERR__FATAL ) {
1220
+ /* No callback defined */
1221
+ return ;
1222
+ }
1223
+
1224
+ cs = CallState_get (h );
1219
1225
1220
1226
/* If the client raised a fatal error we'll raise an exception
1221
1227
* rather than calling the error callback. */
@@ -1226,11 +1232,6 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
1226
1232
goto crash ;
1227
1233
}
1228
1234
1229
- if (!h -> error_cb ) {
1230
- /* No callback defined */
1231
- goto done ;
1232
- }
1233
-
1234
1235
eo = KafkaError_new0 (err , "%s" , reason );
1235
1236
result = PyObject_CallFunctionObjArgs (h -> error_cb , eo , NULL );
1236
1237
Py_DECREF (eo );
@@ -1243,7 +1244,6 @@ static void error_cb (rd_kafka_t *rk, int err, const char *reason, void *opaque)
1243
1244
rd_kafka_yield (h -> rk );
1244
1245
}
1245
1246
1246
- done :
1247
1247
CallState_resume (cs );
1248
1248
}
1249
1249
@@ -1258,12 +1258,14 @@ static void throttle_cb (rd_kafka_t *rk, const char *broker_name, int32_t broker
1258
1258
PyObject * result , * args ;
1259
1259
CallState * cs ;
1260
1260
1261
- cs = CallState_get ( h );
1261
+ /* Avoid grabbing the GIL if it's not needed */
1262
1262
if (!h -> throttle_cb ) {
1263
1263
/* No callback defined */
1264
- goto done ;
1264
+ return ;
1265
1265
}
1266
1266
1267
+ cs = CallState_get (h );
1268
+
1267
1269
ThrottleEvent_type = cfl_PyObject_lookup ("confluent_kafka" ,
1268
1270
"ThrottleEvent" );
1269
1271
@@ -1309,11 +1311,12 @@ static int stats_cb(rd_kafka_t *rk, char *json, size_t json_len, void *opaque) {
1309
1311
PyObject * eo = NULL , * result = NULL ;
1310
1312
CallState * cs = NULL ;
1311
1313
1314
+ /* Avoid calling the GIL if it's not needed */
1315
+ if (json_len == 0 ) {
1316
+ /* No data returned*/
1317
+ goto done ;
1318
+ }
1312
1319
cs = CallState_get (h );
1313
- if (json_len == 0 ) {
1314
- /* No data returned*/
1315
- goto done ;
1316
- }
1317
1320
1318
1321
eo = Py_BuildValue ("s" , json );
1319
1322
result = PyObject_CallFunctionObjArgs (h -> stats_cb , eo , NULL );
0 commit comments