Class to make the launch of the flask server non-blocking. Also adds shutdown functionality to it.
| 62 | app = Flask(__name__, static_url_path='') |
| 63 | |
| 64 | class WebServerThread(Thread): |
| 65 | ''' |
| 66 | Class to make the launch of the flask server non-blocking. |
| 67 | Also adds shutdown functionality to it. |
| 68 | ''' |
| 69 | def __init__(self, app, host, port): |
| 70 | Thread.__init__(self) |
| 71 | self.srv = make_server(host, port, app) |
| 72 | self.ctx = app.app_context() |
| 73 | self.ctx.push() |
| 74 | |
| 75 | def run(self): |
| 76 | logging.info('Starting Flask server') |
| 77 | self.srv.serve_forever() |
| 78 | |
| 79 | def shutdown(self): |
| 80 | logging.info('Stopping Flask server') |
| 81 | self.srv.shutdown() |
| 82 | |
| 83 | @app.route("/robot", methods = ["POST"]) |
| 84 | def robot_commands(): |