-
-
Couldn't load subscription status.
- Fork 339
Receiving "TypeError: cannot pickle '_thread.lock' object" with providers.Factory #718
-
I am using providers.Factory to create a service, and one of the dependencies is a class to interact with our Redis database.
This line in the code seems to be the offender:
self._client = redis.Redis(host=host, port=port, password=password, db=db, health_check_interval=health_check_interval)
that code is executing in the constructor. if I remove that line or if I change it to
client = redis.Redis(host=host, port=port, password=password, db=db, health_check_interval=health_check_interval)
which doesn't help me but just an observation--then there is no error. I understand what pickling is, but I don't understand what is going on here exactly.
Beta Was this translation helpful? Give feedback.
All reactions
-
😕 1
Replies: 1 comment
-
You cannot pass the Redis object directly (or whatever other object). Instead, you need to wrap it with a providers.Object(.). Refer to the documentation.
It would be something like this
# import are here to avoid ambiguity
from dependency_injector import providers
client = providers.Object(redis.Redis(host=host, ...))
Hope it helps.
Beta Was this translation helpful? Give feedback.