Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Carl HR
3 years agoHelpful | Level 6
Is the python dropbox api thread safe?
I'm using different dropbox contexts created with dropbox.Dropbox(...). In my application, I have two or more contexts sharing the same target account (and Console Apps) at a time. Example: contexts ...
Greg-DB
Dropbox Community Moderator
3 years agoI don't believe we currently have any documented guarantee as to whether or not the Python SDK itself is thread-safe, so I can't make assurances on that, but I'll pass this along as a request to the team for that. I can't promise if or when that might be done though.
For reference though, the Dropbox Python SDK uses the requests library to perform the network requests to the Dropbox API. The Dropbox API servers will automatically take locks on resources as needed, e.g., on "namespaces". Check out this guide for more information on that server-side behavior.
Carl HR
3 years agoHelpful | Level 6
Turns out that this answer is not very easy to answer, as even the requests module don't assure wether their api is thread safe.
Going as far to search on stackoverflow and reading the requests module source code , I found out that:
1. Sharing a single session instance on multiple threads is not thread-safe. However, apparently using one instance per thread is. So, in order to use this api correctly, we'd theoretically need to create different dropbox sessions per thread, in order to run code with thread safety.
2. Most of the thread-safety of the requests.sessions module depends on wether the urllib3 module is thread-safe. From current records, it turns out that the v2.0 is thread-safe, as seen on this GitHub thread, and on the urllib official docs .
Though imho its best to stick with option #1 as it's more reliable.
- Здравко3 years agoLegendary | Level 20
Hi Carl HR,
I think, you have misinterpreted the topics you have read. The thread safety there is evaluated in regards of ability to transfer session state between threads (something not guaranteed while using default Python requests library). When everything (Dropbox API call needs) is set explicitly, you don't need to care about any loss of state (no state - there is nothing to loss). The underlying library (urllib3, by the way no curl or some fork of libcurl otherwise available too), that carry the actual request, is thread safe. 😉 You have everything you need with one exception - don't share Dropbox client object between threads. The behavior on refresh would be undefined (something easy correctable with redefining 'check_and_refresh_access_token' - enclose the body in mutex).
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!