You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implementation of ApiClient in the file hoprd_sdk/api_client.py leaves a semaphore not cleaned-up after the instantiated ApiClient finishes his work.
This behaviour is also documented here in OpenAPI/openapi-generator PR #5094
The following modification seams to solve this problem:
importing atexit library
remove __del__ method
adding:
def__enter__(self):
returnselfdef__exit__(self, exc_type, exc_value, traceback):
self.close()
defclose(self):
ifself._pool:
self._pool.close()
self._pool.join()
self._pool=Noneifhasattr(atexit, "unregister"):
atexit.unregister(self.close)
@propertydefpool(self):
"""Create thread pool on first request, avoids instantiating unused threadpool for blocking clients."""ifself._poolisNone:
atexit.register(self.close)
self._pool=ThreadPool()
returnself._pool
removing self.pool = ThreadPool() from the __init__ method
adding _pool = None as class attribute
With the proposed modifications, one can and should use the ApiClient class within a context manager as in the following snippet:
The main problem here is that the SDK is autogenerated, and for future version, doing this patch manually should be avoided.
In the new sdk v3, this solution has already been implemented. A long-term solution should by planned. Maybe using OpenAPI instead of Swagger can solve this.
The text was updated successfully, but these errors were encountered:
The implementation of
ApiClient
in the filehoprd_sdk/api_client.py
leaves a semaphore not cleaned-up after the instantiatedApiClient
finishes his work.This behaviour is also documented here in OpenAPI/openapi-generator PR #5094
The following modification seams to solve this problem:
atexit
library__del__
methodself.pool = ThreadPool()
from the__init__
method_pool = None
as class attributeWith the proposed modifications, one can and should use the
ApiClient
class within a context manager as in the following snippet:The main problem here is that the SDK is autogenerated, and for future version, doing this patch manually should be avoided.
In the new sdk v3, this solution has already been implemented. A long-term solution should by planned. Maybe using OpenAPI instead of Swagger can solve this.
The text was updated successfully, but these errors were encountered: