From a2ba3511cd61770c608b4e39a4c88e4910334846 Mon Sep 17 00:00:00 2001 From: kngwyu Date: Wed, 14 Apr 2021 12:06:56 +0900 Subject: [PATCH] Fix server shutdown --- MANIFEST.in | 3 ++- mujoco_maze/maze_env.py | 8 ++++---- mujoco_maze/static/favicon.ico | Bin 0 -> 2040 bytes 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 mujoco_maze/static/favicon.ico diff --git a/MANIFEST.in b/MANIFEST.in index fd381a6..67ae514 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ -include mujoco-maze/static/index.html \ No newline at end of file +include mujoco-maze/static/favicon.ico +include mujoco-maze/templates/index.html \ No newline at end of file diff --git a/mujoco_maze/maze_env.py b/mujoco_maze/maze_env.py index 2542f67..7e7a68f 100644 --- a/mujoco_maze/maze_env.py +++ b/mujoco_maze/maze_env.py @@ -370,7 +370,6 @@ class MazeEnv(gym.Env): super().__init__() self.pipe = pipe self.port = port - self.server = None def _run_server(self) -> None: import asyncio @@ -384,6 +383,7 @@ class MazeEnv(gym.Env): app = fastapi.FastAPI() html_path = pathlib.Path(__file__).parent.joinpath("static/index.html") html = html_path.read_text().replace("{{port}}", str(self.port)) + server = None @app.get("/") async def get(): @@ -403,11 +403,11 @@ class MazeEnv(gym.Env): res = stream.getvalue() await websocket.send_bytes(res) await websocket.close() - await self.server.shutdown() + server.should_exit = True config = uvicorn.Config(app, port=self.port) - self.server = uvicorn.Server(config) - self.server.run() + server = uvicorn.Server(config) + server.run() def run(self) -> None: try: diff --git a/mujoco_maze/static/favicon.ico b/mujoco_maze/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..45acf83b6535edeae3c9da3588404583625b926b GIT binary patch literal 2040 zcmV}tqtHPiUI&73Q=Fq(EwO$c~md>@V$3<)p|Z#@z;Mp z#W{x{D6PspopmH}g0+?~4DmdlBu+@;1mE`v!w_pNNu1ztgkgv=rp!rFf*>FaL-H&q zPP11Y4$y7X$kL1?PEcAA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