braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
241 stars 155 forks source link

Is this library thread-safe? #131

Closed inikolaev closed 1 year ago

inikolaev commented 3 years ago

I couldn't find any information on whether BraintreeGateway is thread-safe or not - could you help me out with that?

hollabaq86 commented 3 years ago

:wave: @inikolaev to our knowledge we're not doing any operations with shared memory or managing threads. Can you elaborate on your setup? We're curious why you need to confirm this.

inikolaev commented 3 years ago

👋 @inikolaev to our knowledge we're not doing any operations with shared memory or managing threads. Can you elaborate on your setup? We're curious why you need to confirm this.

Sure! We use FastAPI with asyncio, but since this library doesn't yet support asyncio we need to use it from within a thread pools as to not block event loop. I'm trying to understand whether we should create a thread local instance or we could safely use a single instances from multiple threads.

Didn't want to run into any issues, thus decided to ask first to make sure :)

hollabaq86 commented 1 year ago

Sorry that we dropped off on continuing this conversation! I spent some time groking thread safe operations within python, and to my knowledge this library should be safe. We are not using any thread pools in the library.

That said, if anyone does discover an issue within this library that impact thread safety, please open an issue and give us steps to reproduce so we can investigate more deeply.