add safety adapters, configuration handling, server + clients

This commit is contained in:
Ashwin Bharambe 2024-08-03 19:46:59 -07:00
parent 9dafa6ad94
commit fe582a739d
13 changed files with 286 additions and 67 deletions

View file

@ -136,7 +136,7 @@ async def passthrough(
def handle_sigint(*args, **kwargs):
print("SIGINT or CTRL-C detected. Exiting gracefully", args)
print("SIGINT or CTRL-C detected. Exiting gracefully...")
loop = asyncio.get_event_loop()
for task in asyncio.all_tasks(loop):
task.cancel()
@ -198,8 +198,16 @@ def create_dynamic_typed_route(func: Any):
async def endpoint(request: request_model):
try:
return func(request)
return (
await func(request)
if asyncio.iscoroutinefunction(func)
else func(request)
)
except Exception as e:
print(e)
import traceback
traceback.print_exc()
raise translate_exception(e) from e
return endpoint