From 9191cc7cbc50ab28d3d5538c97d25340bf85839b Mon Sep 17 00:00:00 2001 From: boocmp Date: Mon, 3 Jun 2024 19:48:45 +0700 Subject: [PATCH] wait_for instead on timeout. --- src/stt_api.py | 6 ++---- src/utils/npipe/_posix.py | 11 ++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/stt_api.py b/src/stt_api.py index 8a75027..995ab91 100644 --- a/src/stt_api.py +++ b/src/stt_api.py @@ -35,8 +35,9 @@ def to_bytes(self): app = FastAPI() + @app.get("/sticky") -async def handleSticky(request:Request, response: Response, sticky = Cookie(None),): +async def handleSticky(): pass @@ -44,7 +45,6 @@ async def handleSticky(request:Request, response: Response, sticky = Cookie(None async def handleUpstream( pair: str, request: Request, - sticky = Cookie(None), is_valid_brave_key = Depends(check_stt_request) ): if not is_valid_brave_key: @@ -68,8 +68,6 @@ async def handleUpstream( @app.get("/down") async def handleDownstream( pair: str, - request: Request, - sticky = Cookie(None), output: str = "pb", is_valid_brave_key = Depends(check_stt_request) ): diff --git a/src/utils/npipe/_posix.py b/src/utils/npipe/_posix.py index 6bfbb71..594742b 100644 --- a/src/utils/npipe/_posix.py +++ b/src/utils/npipe/_posix.py @@ -18,15 +18,12 @@ def __del__(self): pass async def open(pair: str, timeout: int = 10000): - loop = asyncio.get_running_loop() - try: dir = tempfile.mkdtemp(None, pair + "-", Path.home() / "tmp" / "channels") dir = Path(dir) os.mkfifo(dir / "pipe") - async with asyncio.timeout(timeout / 1000.0): - fd = await aiofiles.open(dir / "pipe", "w") - return AsyncChannelWriter(fd, dir) + fd = await asyncio.wait_for(aiofiles.open(dir / "pipe", "w"), timeout / 1000.0) + return AsyncChannelWriter(fd, dir) except: await aiofiles.os.unlink(dir / "pipe") @@ -53,10 +50,6 @@ async def write(self, data): await self._fd.write(data) await self._fd.flush() - async def writeline(self, data): - await self._fd.writelines([data]) - await self._fd.flush() - class AsyncChannelReader: def __init__(self, fd):