http: Handle getting correct IOLoop when running on tornado < 3.0

This commit is contained in:
Thomas Adamcik 2015-04-24 23:51:14 +02:00
parent b0000404f5
commit a72c9c88c9
2 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,14 @@ Changelog
This changelog is used to track all major changes to Mopidy.
v1.0.2 (unreleased)
===================
Bug fix release.
- HTTP: Make event broadcasts work with Tornado 2.3, the previous threading fix
broke this.
v1.0.1 (2015-04-23)
===================

View File

@ -88,9 +88,13 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
@classmethod
def broadcast(cls, msg):
if hasattr(tornado.ioloop.IOLoop, 'current'):
loop = tornado.ioloop.IOLoop.current()
else:
loop = tornado.ioloop.IOLoop.instance() # Fallback for 2.3
# This can be called from outside the Tornado ioloop, so we need to
# safely cross the thread boundary by adding a callback to the loop.
loop = tornado.ioloop.IOLoop.current()
for client in cls.clients:
# One callback per client to keep time we hold up the loop short
loop.add_callback(_send_broadcast, client, msg)