Giter VIP home page Giter VIP logo

vercel-python's Introduction

@imptype/vercel-python

This is a copy of @vercel/[email protected] except with 2 things changed in vc_init.py:

  1. Uses a shared event loop.

Vercel does asyncio.new_event_loop() every new request, which leads to RuntimeError being raised if 2 requests use/create a resource that was created on a different event loop, for example asyncio.Tasks and a global aiohttp.ClientSession object. It also looks like Vercel makes every new request go through the sync function vc_handler(). So we run an event loop on a separate thread and make all requests use that one loop.

  1. 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 GeneratorExit on it. Finally, this only supports Starlette's lifespan which located in app.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

vercel-python's People

Contributors

imptype avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.