diff --git a/README.md b/README.md index 3ccc369..0e8d84c 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,6 @@ async def show(): - example/with_fastapi.py 与fastapi 配合使用的例子 -- example/error_handler.py - 错误处理的例子 ## TODO diff --git a/blive/eeframework.py b/blive/eeframework.py index 1518d1b..e4b92c3 100644 --- a/blive/eeframework.py +++ b/blive/eeframework.py @@ -87,7 +87,7 @@ class BLiver(AsyncIOEventEmitter): self.scheduler.start() # 开始监听 - while True: + while self.running: try: msg = await self.ws.receive(timeout=60) if msg.type in ( @@ -95,8 +95,9 @@ class BLiver(AsyncIOEventEmitter): aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.ERROR, ): - await self.connect() # reconnect - continue + if self.running: + await self.connect() # reconnect + continue if msg.type != aiohttp.WSMsgType.BINARY: continue mq = self.packman.unpack(msg.data) @@ -112,10 +113,11 @@ class BLiver(AsyncIOEventEmitter): await self.connect() async def graceful_close(self): - self.scheduler.shutdown() - await self._ws.close() - await self.aio_session.close() self.running = False + self.scheduler.shutdown() + await self.aio_session.close() + await self.ws.close() + def run(self): loop = asyncio.get_event_loop() diff --git a/example/with_fastapi.py b/example/with_fastapi.py index 871b487..91e0ffb 100644 --- a/example/with_fastapi.py +++ b/example/with_fastapi.py @@ -1,3 +1,4 @@ +import uvicorn from fastapi import FastAPI from blive import BLiver, Events from blive.msg import DanMuMsg @@ -41,3 +42,7 @@ async def rm_bliver(roomid: int): @app.get("/show") async def show(): return list(BLIVER_POOL.keys()) + + +if __name__ == "__main__": + uvicorn.run(app) \ No newline at end of file diff --git a/setup.py b/setup.py index 0137cad..089dfc8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("./README.md", "r") as f: setuptools.setup( name="blive", - version="0.0.9", + version="0.1.0", author="cam", author_email="yulinfeng000@gmail.com", long_description=description,