Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Receiving "TypeError: cannot pickle '_thread.lock' object" with providers.Factory #718

Unanswered
chriscoindeskindices asked this question in Q&A
Discussion options

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.

You must be logged in to vote

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /