Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Nov 29, 2023
1 parent 6e55c54 commit 8396027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/fastserve/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from threading import Event, Thread
from typing import Any, Callable, Dict, List

from loguru import logger
from logging import Logger, INFO

logger = Logger(__name__, level=INFO)


class BatchedQueue:
Expand Down
18 changes: 11 additions & 7 deletions src/fastserve/fastserve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Any, List

from fastapi import FastAPI
Expand All @@ -12,15 +13,18 @@ class BaseRequest(BaseModel):

class FastServe:
def __init__(self, batch_size=2, timeout=0.5) -> None:
self.batch_processing = BatchProcessor(
func=self.handle, bs=batch_size, timeout=timeout
)
self._app = FastAPI()

@self._app.on_event("shutdown")
def shutdown_event():
self.batch_processing: BatchProcessor = None

@asynccontextmanager
async def lifespan(app: FastAPI):
self.batch_processing = BatchProcessor(
func=self.handle, bs=batch_size, timeout=timeout
)
yield
self.batch_processing.cancel()

self._app = FastAPI(lifespan=lifespan)

def serve(
self,
):
Expand Down

0 comments on commit 8396027

Please sign in to comment.