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

Remove gevent #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
],
keywords='signalr',
packages=find_packages(),
install_requires=['gevent', 'websocket-client', 'sseclient', 'requests']
install_requires=['websocket-client', 'sseclient', 'requests']
)
17 changes: 10 additions & 7 deletions signalr/_connection.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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))
Expand All @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions signalr/transports/_sse_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions signalr/transports/_ws_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down