Loading roles/host.py +6 −0 Changes for roles/host.py: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -125,6 +125,9 @@ class Host(object): elif cmd == 'request/status': request_id = float(params['request_id']) return self.get_request_status(request_id) elif cmd == 'stop': self.worker_manager.request_stop() return {} elif cmd == 'view/solution': problem_key = params['problem'] solution_id = params['solution'] Loading @@ -150,6 +153,9 @@ class WorkerManager(object): def get_workers(self): return self.workers def request_stop(self): self.broadcast('stop', {}) def broadcast(self, cmd, params): threads = [] Loading roles/solver.py +7 −3 Changes for roles/solver.py: 7 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ class StoppableThread(threading.Thread): super(StoppableThread, self).__init__(target=target, args=args) self._status = 'running' def stop(self): if self._status == 'running': if self.is_running(): self._status = 'stopping' def stopped(self): self._status = 'stopped' Loading Loading @@ -80,18 +80,22 @@ class Solver(object): else: return {'status': 'busy'} def stop_solver(): def stop_solver(self): if self.thread is not None: if self.thread.is_running(): self.thread.stop() self.thread.join() self.thread.join(0.1) self.thread = None return {'status': 'stopped'} def call_api(self, method, cmd, params): if cmd == 'role': return {'role': self.type} elif cmd == 'solve': return self.start_solver(params) elif cmd == 'stop': return self.stop_solver() else: return None static/js/adc2019.js +20 −1 Changes for static/js/adc2019.js: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ class StatusView { }), contentType: 'application/json' }).done((d) => { // TODO: タイムアウトになる時間まで,モーダル表示させる var request_id = d['request_id']; var timeout = d['timeout']; Loading @@ -63,10 +62,28 @@ class StatusView { _this.show_problem(); }) _this.container.find('.stop-button').click(()=>{ _this.stop_solver(); }); _this.get_request_status(request_id, timeout); }); } // 強制停止 stop_solver(){ var _this = this; $.ajax({ type: "GET", dataType: "json", url: "/api/stop", }).done((d) => { _this.request_refresh_timer = 'stopped'; alert(d); }); } get_request_status(request_id, timeout){ var _this = this; $.ajax({ Loading @@ -81,6 +98,8 @@ class StatusView { // console.log(status); if(status == 'done'){ _this.request_refresh_timer = null; }else if(_this.request_refresh_timer == 'stopped'){ _this.request_refresh_timer = null; }else{ _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); } Loading templates/part_problem_status.html +1 −1 Changes for templates/part_problem_status.html: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ 処理中... </div> <div class="modal-footer"> <button type="button" class="btn btn-danger">Stop</button> <button type="button" class="btn btn-danger stop-button">Stop</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> </div> </div> Loading Loading
roles/host.py +6 −0 Changes for roles/host.py: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -125,6 +125,9 @@ class Host(object): elif cmd == 'request/status': request_id = float(params['request_id']) return self.get_request_status(request_id) elif cmd == 'stop': self.worker_manager.request_stop() return {} elif cmd == 'view/solution': problem_key = params['problem'] solution_id = params['solution'] Loading @@ -150,6 +153,9 @@ class WorkerManager(object): def get_workers(self): return self.workers def request_stop(self): self.broadcast('stop', {}) def broadcast(self, cmd, params): threads = [] Loading
roles/solver.py +7 −3 Changes for roles/solver.py: 7 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ class StoppableThread(threading.Thread): super(StoppableThread, self).__init__(target=target, args=args) self._status = 'running' def stop(self): if self._status == 'running': if self.is_running(): self._status = 'stopping' def stopped(self): self._status = 'stopped' Loading Loading @@ -80,18 +80,22 @@ class Solver(object): else: return {'status': 'busy'} def stop_solver(): def stop_solver(self): if self.thread is not None: if self.thread.is_running(): self.thread.stop() self.thread.join() self.thread.join(0.1) self.thread = None return {'status': 'stopped'} def call_api(self, method, cmd, params): if cmd == 'role': return {'role': self.type} elif cmd == 'solve': return self.start_solver(params) elif cmd == 'stop': return self.stop_solver() else: return None
static/js/adc2019.js +20 −1 Changes for static/js/adc2019.js: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ class StatusView { }), contentType: 'application/json' }).done((d) => { // TODO: タイムアウトになる時間まで,モーダル表示させる var request_id = d['request_id']; var timeout = d['timeout']; Loading @@ -63,10 +62,28 @@ class StatusView { _this.show_problem(); }) _this.container.find('.stop-button').click(()=>{ _this.stop_solver(); }); _this.get_request_status(request_id, timeout); }); } // 強制停止 stop_solver(){ var _this = this; $.ajax({ type: "GET", dataType: "json", url: "/api/stop", }).done((d) => { _this.request_refresh_timer = 'stopped'; alert(d); }); } get_request_status(request_id, timeout){ var _this = this; $.ajax({ Loading @@ -81,6 +98,8 @@ class StatusView { // console.log(status); if(status == 'done'){ _this.request_refresh_timer = null; }else if(_this.request_refresh_timer == 'stopped'){ _this.request_refresh_timer = null; }else{ _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); } Loading
templates/part_problem_status.html +1 −1 Changes for templates/part_problem_status.html: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ 処理中... </div> <div class="modal-footer"> <button type="button" class="btn btn-danger">Stop</button> <button type="button" class="btn btn-danger stop-button">Stop</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> </div> </div> Loading