Return data in main thread
This commit is contained in:
+5
-2
@@ -7,6 +7,7 @@ import urllib
|
|||||||
|
|
||||||
from couchpotato.core.helpers.request import getParams
|
from couchpotato.core.helpers.request import getParams
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
|
from tornado.ioloop import IOLoop
|
||||||
from tornado.web import RequestHandler, asynchronous
|
from tornado.web import RequestHandler, asynchronous
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +130,10 @@ class ApiHandler(RequestHandler):
|
|||||||
post = get
|
post = get
|
||||||
|
|
||||||
def taskFinished(self, result, route):
|
def taskFinished(self, result, route):
|
||||||
|
IOLoop.current().add_callback(self.sendData, result, route)
|
||||||
|
self.unlock()
|
||||||
|
|
||||||
|
def sendData(self, result, route):
|
||||||
|
|
||||||
if not self.request.connection.stream.closed():
|
if not self.request.connection.stream.closed():
|
||||||
try:
|
try:
|
||||||
@@ -151,8 +156,6 @@ class ApiHandler(RequestHandler):
|
|||||||
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
try: self.finish({'success': False, 'error': 'Failed returning results'})
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
self.unlock()
|
|
||||||
|
|
||||||
def unlock(self):
|
def unlock(self):
|
||||||
try: api_locks[self.route].release()
|
try: api_locks[self.route].release()
|
||||||
except: pass
|
except: pass
|
||||||
|
|||||||
Reference in New Issue
Block a user