diff --git a/couchpotato/api.py b/couchpotato/api.py index 3c8275dc..fbe18b4a 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -7,6 +7,7 @@ import urllib from couchpotato.core.helpers.request import getParams from couchpotato.core.logger import CPLog +from tornado.ioloop import IOLoop from tornado.web import RequestHandler, asynchronous @@ -129,6 +130,10 @@ class ApiHandler(RequestHandler): post = get 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(): try: @@ -151,8 +156,6 @@ class ApiHandler(RequestHandler): try: self.finish({'success': False, 'error': 'Failed returning results'}) except: pass - self.unlock() - def unlock(self): try: api_locks[self.route].release() except: pass