-
Notifications
You must be signed in to change notification settings - Fork 43
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
Implementation of the asyncio consumer #228
base: main
Are you sure you want to change the base?
Conversation
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.
Please remove the binaries from the git commits
Could you also make the tests pass for Python 3.8? Though Python 3.8 will reach EOL on the next month (2024-10) |
I will try to fix the issues this week. |
I found another issue with the schema system in my asyncio implementation, i will fix this too before the next commit. |
Let me fix the broken CI first |
Could you rebase to master to resolve the conflicts and have the CI 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.
@BewareMyPower I removed the binary files |
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.
When you wrap an xxxAsync
API from pulsar-client-cpp, the correct way is:
// release the GIL because xxxAsync does not access any Python objects
py::gil_scoped_release release;
// Pass the callback directly because pybind11 acquires the GIL automatically when the callback is executed
xxx.xxxAsync(yyy, callback);
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.
Please also fix the wrapper in consumer.cc
|
||
namespace py = pybind11; | ||
|
||
void Consumer_unsubscribe(Consumer& consumer) { | ||
waitForAsyncResult([&consumer](ResultCallback callback) { consumer.unsubscribeAsync(callback); }); | ||
} | ||
|
||
void Consumer_unsubscribeAsync(Consumer& consumer, ResultCallback callback) { | ||
consumer.unsubscribeAsync([callback] (Result result) { | ||
py::gil_scoped_acquire acquire; |
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.
This GIL acquire is not necessary
Message Consumer_receive(Consumer& consumer) { | ||
return waitForAsyncValue<Message>([&](ReceiveCallback callback) { consumer.receiveAsync(callback); }); | ||
} | ||
|
||
void Consumer_receiveAsync(Consumer& consumer, ReceiveCallback callback) { | ||
py::gil_scoped_acquire acquire; |
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.
It should release the GIL rather than acquire the GIL
Hi,
I implemented the asyncio consumer in a similar way as the producer. All missing async functions provided by the C++ library are now implemented in the pybind11 classes and I use futures in python to convert the functions with callbacks to async functions. The reason I started with this implementation is because I need the async consumer in a project with FastAPI myself.
Tests could be a little bit patchy, for that reason i would appreciate help if i missed something