Browse Source

Return nonblock results in main thread

pull/4380/head
Ruud 11 years ago
parent
commit
7a1b914824
  1. 14
      couchpotato/api.py
  2. 3
      couchpotato/core/notifications/core/main.py

14
couchpotato/api.py

@ -51,13 +51,10 @@ class NonBlockHandler(RequestHandler):
start, stop = api_nonblock[route]
self.stopper = stop
start(self.onNewMessage, last_id = self.get_argument('last_id', None))
def onNewMessage(self, response):
if self.request.connection.stream.closed():
self.on_connection_close()
return
start(self.sendData, last_id = self.get_argument('last_id', None))
def sendData(self, response):
if not self.request.connection.stream.closed():
try:
self.finish(response)
except:
@ -65,10 +62,11 @@ class NonBlockHandler(RequestHandler):
try: self.finish({'success': False, 'error': 'Failed returning results'})
except: pass
def on_connection_close(self):
self.removeStopper()
def removeStopper(self):
if self.stopper:
self.stopper(self.onNewMessage)
self.stopper(self.sendData)
self.stopper = None

3
couchpotato/core/notifications/core/main.py

@ -14,6 +14,7 @@ from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from .index import NotificationIndex, NotificationUnreadIndex
from couchpotato.environment import Env
from tornado.ioloop import IOLoop
log = CPLog(__name__)
@ -190,7 +191,7 @@ class CoreNotifier(Notification):
while len(self.listeners) > 0 and not self.shuttingDown():
try:
listener, last_id = self.listeners.pop()
listener({
IOLoop.current().add_callback(listener, {
'success': True,
'result': [notification],
})

Loading…
Cancel
Save