Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Update to latest contract and redis versions #10

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

sjhewitt
Copy link
Contributor

Hi &yet!

I've had a go at updating the python version to comply with the latest contract and also use the latest python-redis library.

You'll notice that I've refactored the listener thread out of the Thoonk class into its own class and given it its own redis client instance. This was because there were some problems around calling thoonk.close() that would cause an uncaught error in the listener thread because it's redis connection would disappear. This, however, has introduced something that I find a bit ugly - when you call thoonk.close() it will publish a notice to a unique redis channel that will be picked up by the Listener thread, causing it to unsubscribe from all channels and finish.

I also made a small change to the notice handlers: they are now just called 'publish', 'create', 'configure', etc without the "_notice" suffix (it just seemed a bit redundant!)

@sjhewitt sjhewitt mentioned this pull request Nov 18, 2011
@cpisto
Copy link

cpisto commented Nov 22, 2011

Looks great with one caveat,

Not a fan of the listener thread refactor- why wouldn't you simply use a threading.Event to tell the listener thread to shutdown?

@sjhewitt
Copy link
Contributor Author

The listener thread is blocking on the listen call, meaning it can't respond to an event until it has received a published message. It would be possible to check if the event has been set at the end of the listen loop, and call unsubscribe at that point, though that requires someone to send a message on a channel that it's subscribed to!

The other option is to just kill its redis connection and catch the exception.... it's not a very nice option though!

@cpisto
Copy link

cpisto commented Nov 22, 2011

Gotcha, hadn't noticed the listen interface for redis-py doesn't support a timeout. Pretty ugly :(

@cpisto
Copy link

cpisto commented Nov 22, 2011

I may have a go at refactoring the ThoonkListener back to a happy medium with the master branch (a separate class but not a subclass of threading.Thread), as its pretty nice to be able to be able to run the listener in the main thread, for example in an eventlet/gevent websocket server, so you don't have to keep a separate thread per connection.

Thanks for getting this up to speed on latest redis-py!

@sjhewitt
Copy link
Contributor Author

sounds good... I started trying to implement a Tornado ioloop version of the thoonk library and refactored most of the listener stuff into a common class that could be mixed in to any implementation. Then the ioloop started to hurt my head and I gave up. I'll try and post the code up later.

@sjhewitt
Copy link
Contributor Author

@cpisto - I did the refactor like this: https://gist.github.com/1392377
Let me know what you think!

@cpisto
Copy link

cpisto commented Nov 28, 2011

That looks perfect!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants