redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Thread-safety documentation contradiction?

Open meshantz opened this issue 1 year ago • 0 comments

I'm not sure if this is a bug, documentation oversight, or just a misunderstanding on my part.

Version: Current master at b7f9a4c02aeb687d4db307a63cff0fb24aaec427

Description:

I'm messing around with pubsub, and I'm trying to wrap my head around something here.

https://redis-py.readthedocs.io/en/stable/advanced_features.html#a-note-about-threading mentions:

It is not safe to pass PubSub or Pipeline objects between threads.

Then farther down the page, https://redis-py.readthedocs.io/en/stable/advanced_features.html#publish-subscribe has an explanation of pubsub.run_in_thread (which I'm not intending to do, but I'm looking at what's involved in doing a thread-safe get_message call).

But the implementation https://github.com/redis/redis-py/blob/master/redis/client.py#L1162-L1223 looks like it violates the advice of not passing a PubSub to a thread. It seems like there's an assumption that you won't do anything else with that pubsub instance here, but I don't see that made explicit anywhere, so I'd call the implementation "technically not thread-safe".

Am I misunderstanding something? Is there something else going on here?

meshantz avatar Jun 28 '24 12:06 meshantz