-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Helpers for bulk
method such as async_bulk
sleep in blocking manner, preventing graceful shutdown
#2484
Comments
Example code that our product calls when using the client: https://github.com/elastic/connectors/blob/main/connectors/es/sink.py (see comment on top of the file on how we collect and ingest data). In short, we have a
|
Sorry for the delay Artem. I would be happy to implement the first version, allowing the sleep function to be user-defined. Silently cancelling all sleeps/bulks isn't something we'd want in the general case. |
Hi, I and @girolamo-giordano are working on this, just to understand better: you want a function that is passed in input during the client instantiation, that manage the pressing of CTRL+C and in general how to terminate it. |
Hey @LorenzoFasolino and @girolamo-giordano, please tell me if this snippet clarifies things: import asyncio
async def fake_bulk(sleep=asyncio.sleep):
print("start bulk, sleep 5")
await sleep(5)
async def silently_cancelled_sleep(seconds):
try:
await asyncio.sleep(seconds)
except asyncio.CancelledError:
print("silently ignoring cancellation")
async def main():
print("Calling with silently_cancelled_sleep, Ctrl-C will not raise")
await fake_bulk(silently_cancelled_sleep)
print("Calling with defaults, Ctrl-C will raise")
await fake_bulk()
print("Done")
asyncio.run(main()) The idea is to add this new @artem-shelkovnikov Would this actually solve your problem? Or do you need something else? |
It should solve our problem, yes :) |
We tried using
async_bulk
andasync_streaming_bulk
helpers to ingest data into Elasticsearch and they work great, but we've found out that they prevent our code from gracefully shutting down when CTRL+C is pressed.Example code that sleeps:
elasticsearch-py/elasticsearch/_async/helpers.py
Lines 249 to 251 in e1603f4
It would be great to have a way to:
The text was updated successfully, but these errors were encountered: