Skip to content

add daemon option to PubSubWorker so ctrl-c will work #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2362,22 +2362,23 @@ def handle_message(self, response, ignore_subscribe_messages=False):

return message

def run_in_thread(self, sleep_time=0):
def run_in_thread(self, sleep_time=0, daemon=False):
for channel, handler in iteritems(self.channels):
if handler is None:
raise PubSubError("Channel: '%s' has no handler registered")
for pattern, handler in iteritems(self.patterns):
if handler is None:
raise PubSubError("Pattern: '%s' has no handler registered")

thread = PubSubWorkerThread(self, sleep_time)
thread = PubSubWorkerThread(self, sleep_time, daemon=daemon)
thread.start()
return thread


class PubSubWorkerThread(threading.Thread):
def __init__(self, pubsub, sleep_time):
def __init__(self, pubsub, sleep_time, daemon=False):
super(PubSubWorkerThread, self).__init__()
self.daemon = daemon
self.pubsub = pubsub
self.sleep_time = sleep_time
self._running = False
Expand Down