-
Notifications
You must be signed in to change notification settings - Fork 922
Release GIL prior to blocking (#412) #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
confluent_kafka/src/Consumer.c
Outdated
@@ -595,8 +595,10 @@ static PyObject *Consumer_committed (Handle *self, PyObject *args, | |||
if (!(c_parts = py_to_c_parts(plist))) | |||
return NULL; | |||
|
|||
err = rd_kafka_committed(self->rk, c_parts, | |||
tmout >= 0 ? (int)(tmout * 1000.0f) : -1); | |||
Py_BEGIN_ALLOW_THREADS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the Python docs advocate the use of this macro, but it is bad practice in C to design and use macros that end up with invalid C syntax (even though the expanded macro of course is correct).
This will mess up indentation.
Looking at the macro it should be safe to append a ;
to each of those two lines, or even:
Py_BEGIN_ALLOW_THREADS {
...
} PY_BEGIN_END_ALLOW_THREADS;
But try with just ; first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively I can use PyEval_SaveThread
and PyEval_RestoreThread
directly. Dealer's choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if we are going to break convention anyway we might as well keep it consistent with the others. I'll go ahead and replace the macros with PyEval_SaveThread
and PyEval_RestoreThread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, using the existing macros will make the code future-proof if additional calls are added in upcoming Python versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can fix them all at the same time! #consistency
I see your point, I'll fix the syntax.
@edenhill fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.