-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Is Session/Client thread or asyncio safe? #1088
Comments
asyncio loops are not thread safe, each thread has a separate loop |
So no for 1/2/3/4, due to @thehesiod's point which implies session/client are attached to a single asyncio loop (which is what you would expect). Just tested 5/6 and the answer appears to be yes for those: you can reuse both session and client. I wrote, then read 3 files simultaneously from S3 and all tasks gave the correct results. |
ya 5 and 6 are yes. A client has N tcp connectors you can use at a time in a loop (it's configurable via the Config object) |
@thehesiod I am creating a single "sagemaker-runtime" client and just want to keep using it. |
@mohitk1995 this is the same answer as for botocore. I believe the only way to override the endpoint is via a client constructor (https://github.com/boto/botocore/blob/develop/botocore/session.py#L839) |
going to close as I think we answered the main question. botocore is not cross thread safe, neither is aiobotocore. Given aiobotocore is async, it's tied to a specific run loop, which itself is tied to a specific thread. So |
The in the boto3 docs it says Session objects are not thread safe. See here, which mentions clients are threadsafe once created, but not session or resource. I was wondering what kind of safety we get with a aiobotocore:
The thread safety guards in the underlying botocore I'm guessing can't guarantee 4, e.g. threading and asyncio synchronization primitives are different.
The text was updated successfully, but these errors were encountered: