@imptype/vercel-python
v4.3.35
Published
This is a copy of [@vercel/[email protected]][1] except with 2 things changed in `vc_init.py`:
Readme
@imptype/vercel-python
This is a copy of @vercel/[email protected] except with 2 things changed in vc_init.py:
- Uses a shared event loop.
Vercel does
asyncio.new_event_loop()every new request, which leads toRuntimeErrorbeing raised if 2 requests use/create a resource that was created on a different event loop, for exampleasyncio.Tasksand a globalaiohttp.ClientSessionobject. It also looks like Vercel makes every new request go through the sync functionvc_handler(). So we run an event loop on a separate thread and make all requests use that one loop.
- Runs the
__aenter__part of lifespan.
Vercel does not support lifespan. Lifespan is used init async code, like creating a database connection pool. This runs once per instance, not per request, so whatever is in there contributes to the coldstart time. A reference is kept so the Garbage Collector won't silently raise
GeneratorExiton it. Finally, this only supports Starlette's lifespan which located inapp.router.lifespan_context. This part will be skipped if no lifespan was found.
Usage
In your vercel.json file, change the npm package to use to @imptype/[email protected], for example:
{
"builds": [
{
"src": "main.py",
"use": "@imptype/[email protected]"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "main.py"
}
]
}Stable versions
- 3.4.12 - Uses shared event loop
- 3.4.35 - Uses shared event loop and runs the
__aenter__part of lifespan
