Return nonblock results in main thread
This commit is contained in:
+12
-14
@@ -51,24 +51,22 @@ class NonBlockHandler(RequestHandler):
|
|||||||
start, stop = api_nonblock[route]
|
start, stop = api_nonblock[route]
|
||||||
self.stopper = stop
|
self.stopper = stop
|
||||||
|
|
||||||
start(self.onNewMessage, last_id = self.get_argument('last_id', None))
|
start(self.sendData, last_id = self.get_argument('last_id', None))
|
||||||
|
|
||||||
def onNewMessage(self, response):
|
def sendData(self, response):
|
||||||
if self.request.connection.stream.closed():
|
if not self.request.connection.stream.closed():
|
||||||
self.on_connection_close()
|
try:
|
||||||
return
|
self.finish(response)
|
||||||
|
except:
|
||||||
|
log.debug('Failed doing nonblock request, probably already closed: %s', (traceback.format_exc()))
|
||||||
|
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
||||||
|
except: pass
|
||||||
|
|
||||||
try:
|
self.removeStopper()
|
||||||
self.finish(response)
|
|
||||||
except:
|
|
||||||
log.debug('Failed doing nonblock request, probably already closed: %s', (traceback.format_exc()))
|
|
||||||
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
|
||||||
except: pass
|
|
||||||
|
|
||||||
def on_connection_close(self):
|
|
||||||
|
|
||||||
|
def removeStopper(self):
|
||||||
if self.stopper:
|
if self.stopper:
|
||||||
self.stopper(self.onNewMessage)
|
self.stopper(self.sendData)
|
||||||
|
|
||||||
self.stopper = None
|
self.stopper = None
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from couchpotato.core.logger import CPLog
|
|||||||
from couchpotato.core.notifications.base import Notification
|
from couchpotato.core.notifications.base import Notification
|
||||||
from .index import NotificationIndex, NotificationUnreadIndex
|
from .index import NotificationIndex, NotificationUnreadIndex
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
|
from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
@@ -190,7 +191,7 @@ class CoreNotifier(Notification):
|
|||||||
while len(self.listeners) > 0 and not self.shuttingDown():
|
while len(self.listeners) > 0 and not self.shuttingDown():
|
||||||
try:
|
try:
|
||||||
listener, last_id = self.listeners.pop()
|
listener, last_id = self.listeners.pop()
|
||||||
listener({
|
IOLoop.current().add_callback(listener, {
|
||||||
'success': True,
|
'success': True,
|
||||||
'result': [notification],
|
'result': [notification],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user