diff --git a/CHANGES.rst b/CHANGES.rst index e089d9d..c07e2a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,8 @@ develop * Fail on start if any child threads can't start (eg: port in use). * Add missing versions and dates to the change log, and note on Semantic Versioning. +* Emit `django.core.signals.request_finished` to close DB connection and + yield to other greenlets between processing messages from WebSocket. * Back to universal wheels, thanks to PEP-0496 environment markers. * Fix for #23 (Python 3 compatibility). * Set `application_name` on PostgreSQL async connection. diff --git a/dddp/websocket.py b/dddp/websocket.py index 8a2f4d8..b6ecfa0 100644 --- a/dddp/websocket.py +++ b/dddp/websocket.py @@ -12,6 +12,7 @@ import traceback from six.moves import range as irange import ejson +import gevent import geventwebsocket from django.core import signals from django.core.handlers.base import BaseHandler @@ -197,6 +198,11 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication): except Exception as err: traceback.print_exc() self.error(err) + # emit request_finished signal to close DB connections + signals.request_finished.send(sender=self.__class__) + if msgs: + # yield to other greenlets before processing next msg + gevent.sleep() except geventwebsocket.WebSocketError as err: self.ws.close()