diff options
author | Timothy Rule <34501912+trulede@users.noreply.github.com> | 2019-07-28 21:42:33 +0200 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2019-07-28 12:42:33 -0700 |
commit | 6ce11f130d3bd7106e4879db70d77c5708d2898e (patch) | |
tree | e29e42d50e2d40243e3fcb1b1b416ccc3f0fa19d | |
parent | f60b2b07caba276b9308340b8ea06e5844f3f0ab (diff) | |
download | redis-py-6ce11f130d3bd7106e4879db70d77c5708d2898e.tar.gz |
Add an Event parameter to PubSubWorkerThread and run_in_thread so (#1195)
The PubSubWorkerThread now uses a `threading.Event` to control its life cycle.
-rwxr-xr-x | redis/client.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py index 80ffb68..fb1297a 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3372,15 +3372,15 @@ class PubSubWorkerThread(threading.Thread): self.daemon = daemon self.pubsub = pubsub self.sleep_time = sleep_time - self._running = False + self._running = threading.Event() def run(self): - if self._running: + if self._running.is_set(): return - self._running = True + self._running.set() pubsub = self.pubsub sleep_time = self.sleep_time - while self._running: + while self._running.is_set(): pubsub.get_message(ignore_subscribe_messages=True, timeout=sleep_time) pubsub.close() @@ -3389,7 +3389,7 @@ class PubSubWorkerThread(threading.Thread): # trip the flag so the run loop exits. the run loop will # close the pubsub connection, which disconnects the socket # and returns the connection to the pool. - self._running = False + self._running.clear() class Pipeline(Redis): |