From b38a0447f66b7562abc4d99ed680c60c65074902 Mon Sep 17 00:00:00 2001 From: Tyson Clugg Date: Wed, 16 Dec 2015 17:24:45 +1100 Subject: [PATCH] Close DB and yield after processing msg from WebSocket. --- CHANGES.rst | 2 ++ dddp/websocket.py | 6 ++++++ 2 files changed, 8 insertions(+) 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()