Skip to content

Commit

Permalink
add queueing and multi process
Browse files Browse the repository at this point in the history
  • Loading branch information
Peddle committed Dec 7, 2023
1 parent f21f811 commit bc1aab9
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 180 deletions.
18 changes: 17 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from potassium import Potassium, Request, Response
from transformers import pipeline
import torch
import os

app = Potassium("my_app")

Expand Down Expand Up @@ -28,5 +30,19 @@ def handler(context: dict, request: Request) -> Response:
status=200
)

@app.handler("/stream")
def stream(context: dict, request: Request):
def stream():
for i in range(100):
yield f"{i}\n"
time.sleep(1)

return Response(
body=stream(),
status=200,
headers={"Content-Type": "text/plain"}
)


if __name__ == "__main__":
app.serve()
app.serve()
3 changes: 2 additions & 1 deletion potassium/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .potassium import *
from .hooks import *
from .store import Store, RedisConfig
from .store import Store, RedisConfig
from .types import Request, Response
10 changes: 10 additions & 0 deletions potassium/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class InvalidEndpointTypeException(Exception):
def __init__(self):
super().__init__("Invalid endpoint type. Must be 'handler' or 'background'")


class RouteAlreadyInUseException(Exception):
def __init__(self):
super().__init__("Route already in use")


Loading

0 comments on commit bc1aab9

Please sign in to comment.