Skip to content

Commit

Permalink
wait_for instead on timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
boocmp committed Jun 3, 2024
1 parent 1e94f33 commit 9191cc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/stt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def to_bytes(self):

app = FastAPI()


@app.get("/sticky")
async def handleSticky(request:Request, response: Response, sticky = Cookie(None),):
async def handleSticky():
pass


@app.post("/up")
async def handleUpstream(
pair: str,
request: Request,
sticky = Cookie(None),
is_valid_brave_key = Depends(check_stt_request)
):
if not is_valid_brave_key:
Expand All @@ -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)
):
Expand Down
11 changes: 2 additions & 9 deletions src/utils/npipe/_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down

0 comments on commit 9191cc7

Please sign in to comment.