Thread safe query
Author: TiergartenCreated Sep 8, 2021Updated Sep 12, 2025
Is python-binance a thread safe library?
The output from from the http request method is being assigned to a class variable (self.response). This is not being used any where else in the code.
def _request(self, method, uri: str, signed: bool, force_params: bool = False, **kwargs):
kwargs = self._get_request_kwargs(method, signed, force_params, **kwargs)
self.response = getattr(self.session, method)(uri, **kwargs)
return self._handle_response(self.response)I have code which executes queries via this library from multiple threads. This use of this shared variable looks like it has the potential to cause race conditions.
Happy to raise a PR if this can be replaced with a local method variable.
Source: sammchardy/python-binance