def post(self): if self.debug and self.get_argument('error', u''): # for testing purpose only raise ValueError('Uncaught exception') self.src_addr = self.get_client_addr() if len(clients.get(self.src_addr[0], {})) >= options.maxconn: raise tornado.web.HTTPError(403, 'Too many connections.') future = Future() t = threading.Thread(target=self.ssh_connect_wrapped, args=(future,)) t.setDaemon(True) t.start() try: worker = yield future except (ValueError, paramiko.SSHException) as exc: self.result.update(status=str(exc)) else: workers = clients.setdefault(worker.src_addr[0], {}) workers[worker.id] = worker self.loop.call_later(DELAY, recycle_worker, worker) self.result.update(id=worker.id, encoding=worker.encoding) self.write(self.result)
def post(self): if self.debug and self.get_argument('error', u''): # for testing purpose only raise ValueError('Uncaught exception') self.src_addr = self.get_client_addr() if len(clients.get(self.src_addr[0], {})) >= options.maxconn: raise tornado.web.HTTPError(403, 'Too many live connections.') self.check_origin() try: args = self.get_args() except InvalidValueError as exc: raise tornado.web.HTTPError(400, str(exc)) future = self.executor.submit(self.ssh_connect, args) try: worker = yield future except (ValueError, paramiko.SSHException) as exc: logging.error(traceback.format_exc()) self.result.update(status=str(exc)) else: workers = clients.setdefault(worker.src_addr[0], {}) workers[worker.id] = worker self.loop.call_later(DELAY, recycle_worker, worker) self.result.update(id=worker.id, encoding=worker.encoding) self.write(self.result)