Return nonblock results in main thread
This commit is contained in:
1 parent
5e62801666
commit
7a1b914824
2 files changed
+8
-9
No files matched your search
+6
-8
@@ -51,13 +51,10 @@ 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):
|
|
||||||
if self.request.connection.stream.closed():
|
|
||||||
self.on_connection_close()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
def sendData(self, response):
|
||||||
|
if not self.request.connection.stream.closed():
|
||||||
try:
|
try:
|
||||||
self.finish(response)
|
self.finish(response)
|
||||||
except:
|
except:
|
||||||
@@ -65,10 +62,11 @@ class NonBlockHandler(RequestHandler):
|
|||||||
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
def on_connection_close(self):
|
self.removeStopper()
|
||||||
|
|
||||||
|
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