twilio-python
twilio-python copied to clipboard
Is this library thread-safe?
I haven't seen anything in your documentation, code, nor old GH issues that would explicitly say whether this library is or isn't thread-safe (and whether that's even the goal). I think it would be good to address that, especially since sending multiple concurrent requests to Twilio's API is a pretty common use case. A similar question has already been asked & answered for your Java client (https://github.com/twilio/twilio-java/issues/441).
Based on my own (admittedly shallow) investigation, using your Python client may not be thread-safe because:
- By default,
TwilioHttpClient
usesrequests.Session
and there's still an open issue discussing whether that is thread-safe or not. - Using
TwilioHttpClient.last_request
/last_response
is definitely not thread-safe.
Your analysis is correct. Until the thread-safety of requests.Session
can be proven then the thread-safety of the client here cannot made. For last_request/response
, these are intended for testing purposes only and should not be relied upon in a production set up.
Your analysis is correct. Until the thread-safety of
requests.Session
can be proven then the thread-safety of the client here cannot made.
Alright, thanks for confirming my suspicions!
For
last_request/response
, these are intended for testing purposes only and should not be relied upon in a production set up.
Good to know! It would be great to document that in your code, e.g. via a comment above where these fields are first mentioned or via a more obvious variable name, like _test_only_last_request
.
Thanks for the documentation suggestion @wojcikstefan! It's been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.