Closed Azmisov closed 1 month ago
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. Could we make use of this client for calling into four sagemaker endpoints in a async manner? Or we need to create one client for each endpoint?
@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 1.no 2.no 3.no 4.no 5.yes 6.yes
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.