Close DB and yield after processing msg from WebSocket.

This commit is contained in:
Tyson Clugg 2015-12-16 17:24:45 +11:00
parent cb4bf1afa5
commit b38a0447f6
2 changed files with 8 additions and 0 deletions

View file

@ -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.

View file

@ -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()