-
Notifications
You must be signed in to change notification settings - Fork 47
Fixed deadlock in producer.send_async #87
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,16 @@ MessageId Producer_send(Producer& producer, const Message& message) { | |
return messageId; | ||
} | ||
|
||
void Producer_sendAsync(Producer& producer, const Message& msg, SendCallback callback) { | ||
Py_BEGIN_ALLOW_THREADS | ||
producer.sendAsync(msg, callback); | ||
Py_END_ALLOW_THREADS | ||
|
||
if (PyErr_CheckSignals() == -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if an exception was already set in the interpreter global before the callback fired? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in the main thread, irrespective of the callback.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Something I've seen before is issues around an error already being "pre-raise" in a Python thread when some external code (the pulsar client C++ in this case) decides to invoke an unrelated Python callback. Does pybind handle situations like this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All set per conversation on #84 |
||
PyErr_SetInterrupt(); | ||
} | ||
} | ||
|
||
void Producer_flush(Producer& producer) { | ||
waitForAsyncResult([&](ResultCallback callback) { producer.flushAsync(callback); }); | ||
} | ||
|
@@ -67,7 +77,7 @@ void export_producer(py::module_& m) { | |
"This method is equivalent to asyncSend() and wait until the callback is triggered.\n" | ||
"\n" | ||
"@param msg message to publish\n") | ||
.def("send_async", &Producer::sendAsync) | ||
.def("send_async", &Producer_sendAsync) | ||
.def("flush", &Producer_flush, | ||
"Flush all the messages buffered in the client and wait until all messages have been\n" | ||
"successfully persisted\n") | ||
|
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.
Is something inside this line handling getting the GIL around
callback
? Sincecallback
is python code, running it outside of the GIL can break all sorts of stuff.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.
@zbentley PyBind is already acquiring the GIL before it enters the Python callback code.
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.
All set per conversation on #84