diff --git a/DESCRIPTION.rst b/DESCRIPTION.rst index 38e4d38..3810ed0 100644 --- a/DESCRIPTION.rst +++ b/DESCRIPTION.rst @@ -8,13 +8,9 @@ Requirements Install the following prerequisites using `pip`: -* `gevent` * `sseclient` * `websocket-client` -The `gevent` package in turn requires Python headers. -In Debian based distributions (such as Ubuntu and Raspbian) they are called `python-dev`. - Compatibility ------------- diff --git a/README.md b/README.md index cb7349b..8174aa8 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,9 @@ Python client proxy for [SignalR](http://signalr.net/). Install the following prerequisites using `pip`: -* `gevent` * `sseclient` * `websocket-client` -The `gevent` package in turn requires Python headers. -In Debian based distributions (such as Ubuntu and Raspbian) they are called `python-dev`. - ## Compatibility Only compatible with Python 2, not Python 3. diff --git a/setup.py b/setup.py index 6b9117f..98b84c9 100644 --- a/setup.py +++ b/setup.py @@ -25,5 +25,5 @@ ], keywords='signalr', packages=find_packages(), - install_requires=['gevent', 'websocket-client', 'sseclient', 'requests'] + install_requires=['websocket-client', 'sseclient', 'requests'] ) diff --git a/signalr/_connection.py b/signalr/_connection.py index 2e09a3c..a7378a9 100644 --- a/signalr/_connection.py +++ b/signalr/_connection.py @@ -1,9 +1,8 @@ import json -import gevent from signalr.events import EventHook from signalr.hubs import Hub from signalr.transports import AutoTransport - +from threading import Thread class Connection: protocol_version = '1.5' @@ -15,8 +14,9 @@ def __init__(self, url, session): self.connection_token = None self.connection_data = None self.handlers = EventHook() + self.is_open = False self.__transport = AutoTransport(session, self.handlers) - self.__greenlet = None + self.__listener_thread = None def __get_connection_data(self): return json.dumps(map(lambda hub_name: {'name': hub_name}, self.__hubs)) @@ -33,16 +33,19 @@ def start(self): listener = self.__transport.start(self) def wrapped_listener(): - listener() - gevent.sleep(0) + while self.is_open: + listener() - self.__greenlet = gevent.spawn(wrapped_listener) + self.is_open = True + self.__listener_thread = Thread(target=wrapped_listener) + self.__listener_thread.start() def send(self, data): self.__transport.send(self, data) def close(self): - gevent.kill(self.__greenlet) + self.is_open = False + self.__listener_thread.join() self.__transport.close(self) def hub(self, name): diff --git a/signalr/transports/_sse_transport.py b/signalr/transports/_sse_transport.py index 2d12fa1..9764c88 100644 --- a/signalr/transports/_sse_transport.py +++ b/signalr/transports/_sse_transport.py @@ -12,11 +12,17 @@ def _get_name(self): return 'serverSentEvents' def start(self, connection): - self.__response = sseclient.SSEClient(self._get_url(connection, 'connect'), session=self._session) + connect_url = self._get_url(connection, 'connect') + self.__response = \ + iter(sseclient.SSEClient(connect_url, session=self._session)) self._session.get(self._get_url(connection, 'start')) def _receive(): - for notification in self.__response: + try: + notification = next(self.__response) + except StopIteration: + return + else: if notification.data != 'initialized': self._handle_notification(notification.data) diff --git a/signalr/transports/_ws_transport.py b/signalr/transports/_ws_transport.py index 7246ecd..012bec9 100644 --- a/signalr/transports/_ws_transport.py +++ b/signalr/transports/_ws_transport.py @@ -26,9 +26,8 @@ def start(self, connection): cookie=self.__get_cookie_str()) def _receive(): - while True: - notification = self.ws.recv() - self._handle_notification(notification) + notification = self.ws.recv() + self._handle_notification(notification) return _receive