Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add queueing and multi process support #48

Merged
merged 11 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 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,26 @@ def handler(context: dict, request: Request) -> Response:
status=200
)

@app.background("/background")
def background(context: dict, request: Request):
time.sleep(5)
print('hi')


@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
Peddle marked this conversation as resolved.
Show resolved Hide resolved
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
Loading