Skip to content
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

Tornado 4.2 migration (without toro dependency) #16

Merged
merged 11 commits into from
Aug 12, 2015
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tornado==4.1
tornado==4.2.1
hiredis==0.2.0
toro==0.8
six==1.9.0
3 changes: 1 addition & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tornado.testing
import tornado.ioloop
import tornado
import toro
import functools

from tornadis.client import Client
Expand Down Expand Up @@ -56,7 +55,7 @@ def _test_autoconnect_callback_cb(self, condition, result):

@tornado.testing.gen_test
def test_autoconnect_callback(self):
condition = toro.Condition()
condition = tornado.locks.Condition()
c = Client(autoconnect=True)
cb = functools.partial(self._test_autoconnect_callback_cb, condition)
c.async_call('PING', callback=cb)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import tornado.testing
import tornado.ioloop
import toro
import tornado.queues
import errno
import socket
from tornadis.connection import Connection
Expand Down Expand Up @@ -104,7 +104,7 @@ def setUp(self):
test_redis_uds_or_raise_skiptest()
super(AbstractConnectionTestCase, self).setUp()
self.reader = hiredis.Reader()
self.reply_queue = toro.Queue()
self.reply_queue = tornado.queues.Queue()

def _close_cb(self):
pass
Expand Down
16 changes: 11 additions & 5 deletions tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import tornado.testing
import tornado.ioloop
import tornado.gen

from tornadis.pubsub import PubSubClient
from tornadis.client import Client
Expand All @@ -19,6 +20,15 @@ def setUp(self):
def get_new_ioloop(self):
return tornado.ioloop.IOLoop.instance()

@tornado.gen.coroutine
def publish(self, c2):
yield tornado.gen.sleep(1)
yield c2.call("PUBLISH", "null", "value0")
yield c2.call("PUBLISH", "foo1", "value1")
yield c2.call("PUBLISH", "foo2", "value2")
yield c2.call("PUBLISH", "bar111", "value3")
yield c2.call("PUBLISH", "bar222", "value4")

@tornado.testing.gen_test
def test_pubsub(self):
c = PubSubClient()
Expand All @@ -41,11 +51,7 @@ def test_pubsub(self):
pass
res = yield c.pubsub_psubscribe("bar1*", "bar2*")
self.assertTrue(res)
yield c2.call("PUBLISH", "null", "value0")
yield c2.call("PUBLISH", "foo1", "value1")
yield c2.call("PUBLISH", "foo2", "value2")
yield c2.call("PUBLISH", "bar111", "value3")
yield c2.call("PUBLISH", "bar222", "value4")
tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
msg = yield c.pubsub_pop_message()
self.assertEquals(msg[2], b"value1")
msg = yield c.pubsub_pop_message()
Expand Down
4 changes: 2 additions & 2 deletions tornadis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# See the LICENSE file for more information.

import tornado.gen
import tornado.locks
import hiredis
import collections
import functools
import toro
import logging

from tornadis.connection import Connection
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, autoconnect=True, **connection_kwargs):
# Used for normal clients
self.__callback_queue = None
# Used for subscribed clients
self._condition = toro.Condition()
self._condition = tornado.locks.Condition()
self._reply_list = None

@property
Expand Down
6 changes: 3 additions & 3 deletions tornadis/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import tornado.gen
import tornado.ioloop
import toro
import tornado.locks
import logging
import functools
from collections import deque
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, max_size=-1, client_timeout=-1, autoclose=False,
self.autoclose = autoclose
self.__pool = deque()
if self.max_size != -1:
self.__sem = toro.Semaphore(self.max_size)
self.__sem = tornado.locks.Semaphore(self.max_size)
else:
self.__sem = None
self.__autoclose_periodic = None
Expand Down Expand Up @@ -96,7 +96,7 @@ def get_client_nowait(self):
A Client instance (not necessary connected) as result (or None).
"""
if self.__sem is not None:
if self.__sem.locked():
if self.__sem._value == 0:
return None
self.__sem.acquire()
_, client = self._get_client_from_pool_or_make_it()
Expand Down
20 changes: 8 additions & 12 deletions tornadis/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import tornado.ioloop
import tornado.gen
import toro

from tornadis.client import Client
from tornadis.exceptions import ConnectionError, ClientError
Expand Down Expand Up @@ -150,16 +149,13 @@ def pubsub_pop_message(self, deadline=None):
"pubsub_pop_message")
reply = None
try:
try:
reply = self._reply_list.pop(0)
except IndexError:
yield self._condition.wait(deadline=deadline)
except toro.Timeout:
reply = self._reply_list.pop(0)
raise tornado.gen.Return(reply)
except IndexError:
pass
yield self._condition.wait(timeout=deadline)
try:
reply = self._reply_list.pop(0)
except IndexError:
pass
else:
if reply is None:
try:
reply = self._reply_list.pop(0)
except IndexError:
pass
raise tornado.gen.Return(reply)
4 changes: 2 additions & 2 deletions tornadis/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# See the LICENSE file for more information.

import tornado.gen
import toro
import tornado.locks
import datetime


Expand All @@ -17,7 +17,7 @@ class ConnectionState(object):
__condition = None

def __init__(self):
self.__condition = toro.Condition()
self.__condition = tornado.locks.Condition()
self.set_disconnected()

def is_connected(self):
Expand Down