Fix server shutdown
This commit is contained in:
parent
15a1a1384f
commit
a2ba3511cd
@ -1 +1,2 @@
|
|||||||
include mujoco-maze/static/index.html
|
include mujoco-maze/static/favicon.ico
|
||||||
|
include mujoco-maze/templates/index.html
|
@ -370,7 +370,6 @@ class MazeEnv(gym.Env):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.pipe = pipe
|
self.pipe = pipe
|
||||||
self.port = port
|
self.port = port
|
||||||
self.server = None
|
|
||||||
|
|
||||||
def _run_server(self) -> None:
|
def _run_server(self) -> None:
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -384,6 +383,7 @@ class MazeEnv(gym.Env):
|
|||||||
app = fastapi.FastAPI()
|
app = fastapi.FastAPI()
|
||||||
html_path = pathlib.Path(__file__).parent.joinpath("static/index.html")
|
html_path = pathlib.Path(__file__).parent.joinpath("static/index.html")
|
||||||
html = html_path.read_text().replace("{{port}}", str(self.port))
|
html = html_path.read_text().replace("{{port}}", str(self.port))
|
||||||
|
server = None
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def get():
|
async def get():
|
||||||
@ -403,11 +403,11 @@ class MazeEnv(gym.Env):
|
|||||||
res = stream.getvalue()
|
res = stream.getvalue()
|
||||||
await websocket.send_bytes(res)
|
await websocket.send_bytes(res)
|
||||||
await websocket.close()
|
await websocket.close()
|
||||||
await self.server.shutdown()
|
server.should_exit = True
|
||||||
|
|
||||||
config = uvicorn.Config(app, port=self.port)
|
config = uvicorn.Config(app, port=self.port)
|
||||||
self.server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
self.server.run()
|
server.run()
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
try:
|
try:
|
||||||
|
BIN
mujoco_maze/static/favicon.ico
Normal file
BIN
mujoco_maze/static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Loading…
Reference in New Issue
Block a user