Skip to content

Commit e270507

Browse files
authored
closing consumer multiple times should not raise RunTimeError (@mkmoisen , #678)
1 parent 1fdc89b commit e270507

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

confluent_kafka/src/Consumer.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,11 +977,8 @@ static PyObject *Consumer_consume (Handle *self, PyObject *args,
977977
static PyObject *Consumer_close (Handle *self, PyObject *ignore) {
978978
CallState cs;
979979

980-
if (!self->rk) {
981-
PyErr_SetString(PyExc_RuntimeError,
982-
"Consumer already closed");
983-
return NULL;
984-
}
980+
if (!self->rk)
981+
Py_RETURN_NONE;
985982

986983
CallState_begin(self, &cs);
987984

@@ -1296,7 +1293,6 @@ static PyMethodDef Consumer_methods[] = {
12961293
"see :py:func::`poll()` for more info.\n"
12971294
"\n"
12981295
" :rtype: None\n"
1299-
" :raises: RuntimeError if called on a closed consumer\n"
13001296
"\n"
13011297
},
13021298
{ "list_topics", (PyCFunction)list_topics, METH_VARARGS|METH_KEYWORDS,

tests/test_Consumer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def test_offsets_for_times():
209209
c.close()
210210

211211

212-
def test_multiple_close_throw_exception():
213-
""" Calling Consumer.close() multiple times should throw Runtime Exception
212+
def test_multiple_close_does_not_throw_exception():
213+
""" Calling Consumer.close() multiple times should not throw Runtime Exception
214214
"""
215215
c = Consumer({'group.id': 'test',
216216
'enable.auto.commit': True,
@@ -222,10 +222,7 @@ def test_multiple_close_throw_exception():
222222

223223
c.unsubscribe()
224224
c.close()
225-
226-
with pytest.raises(RuntimeError) as ex:
227-
c.close()
228-
assert ex.match('Consumer already closed')
225+
c.close()
229226

230227

231228
def test_any_method_after_close_throws_exception():

0 commit comments

Comments
 (0)