Skip to content
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
28 changes: 23 additions & 5 deletions frameworks/Python/granian/app_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ async def pg_setup():
with Path('templates/fortune.html').open('r') as f:
template = jinja2.Template(f.read())

asyncio.get_event_loop().run_until_complete(pg_setup())


def get_num_queries(scope):
try:
Expand Down Expand Up @@ -178,6 +176,26 @@ async def handle_404(scope, receive, send):
}


def main(scope, receive, send):
handler = routes.get(scope['path'], handle_404)
return handler(scope, receive, send)
class App:
__slots__ = ["_handler"]

def __init__(self):
self._handler = self._lifespan

def __call__(self, scope, receive, send):
return self._handler(scope, receive, send)

async def _lifespan(self, scope, receive, send):
if scope['type'] == 'lifespan':
message = await receive()
if message['type'] == 'lifespan.startup':
await pg_setup()
self._handler = self._asgi
await send({'type': 'lifespan.startup.complete'})

def _asgi(self, scope, receive, send):
handler = routes.get(scope['path'], handle_404)
return handler(scope, receive, send)


main = App()
16 changes: 10 additions & 6 deletions frameworks/Python/granian/app_rsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import os

from operator import itemgetter
Expand Down Expand Up @@ -37,8 +36,6 @@ async def pg_setup():
with Path('templates/fortune.html').open('r') as f:
template = jinja2.Template(f.read())

asyncio.get_event_loop().run_until_complete(pg_setup())


def get_num_queries(scope):
try:
Expand Down Expand Up @@ -152,6 +149,13 @@ async def handle_404(scope, proto):
}


def main(scope, proto):
handler = routes.get(scope.path, handle_404)
return handler(scope, proto)
class App:
def __rsgi_init__(self, loop):
loop.run_until_complete(pg_setup())

def __rsgi__(self, scope, proto):
handler = routes.get(scope.path, handle_404)
return handler(scope, proto)


main = App()
2 changes: 1 addition & 1 deletion frameworks/Python/granian/granian-rsgi.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt

EXPOSE 8080

CMD python run.py rsgi runtime
CMD python run.py rsgi mt
2 changes: 1 addition & 1 deletion frameworks/Python/granian/granian-wrk.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt

EXPOSE 8080

CMD python run.py rsgi workers
CMD python run.py rsgi st
2 changes: 1 addition & 1 deletion frameworks/Python/granian/granian-wsgi.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt

EXPOSE 8080

CMD python run.py wsgi runtime
CMD python run.py wsgi mt
2 changes: 1 addition & 1 deletion frameworks/Python/granian/granian.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN pip install -r /granian/requirements.txt

EXPOSE 8080

CMD python run.py asgi runtime
CMD python run.py asgi mt
2 changes: 1 addition & 1 deletion frameworks/Python/granian/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncpg==0.29.0
granian>=1.7.0,<1.8.0
granian[uvloop]>=2.2.0,<2.3.0
jinja2==3.1.4
orjson==3.10.2
4 changes: 2 additions & 2 deletions frameworks/Python/granian/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if __name__ == '__main__':
interface = sys.argv[1]
threading_mode = sys.argv[2]
runtime_mode = sys.argv[2]
workers = multiprocessing.cpu_count()

if interface == "rsgi":
Expand All @@ -23,7 +23,7 @@
address="0.0.0.0",
port=8080,
workers=workers,
threading_mode=threading_mode,
runtime_mode=runtime_mode,
blocking_threads=blocking_threads,
backlog=16384,
interface=interface,
Expand Down
Loading