Coder Social home page Coder Social logo

Comments (3)

glasah avatar glasah commented on June 16, 2024 1

I can get it working if I set

config.use_reloader = True                                                                                                                                                                                                                                                      

from hypercorn.

pgjones avatar pgjones commented on June 16, 2024

This is a really weird one, if I put the loop in a task and await the serve it works fine. When it does error it is a GeneratorExit being thrown somewhere, I think due to garbage collection, that triggers the error. As a workaround I suggest,

import asyncio

from hypercorn.asyncio import serve
from hypercorn.config import Config
from quart import Quart, request

app = Quart(__name__)


@app.route("/ping", methods=["GET"])
async def ping():
    return "pong"


config = Config()
config.bind = ["localhost:8080"]

async def foo():
    while True:
        print("Hello")
        await asyncio.sleep(1)

async def main():
    await asyncio.gather(
        asyncio.create_task(serve(app, config)),
        asyncio.create_task(foo()),
    ) 

asyncio.run(main())

from hypercorn.

pgjones avatar pgjones commented on June 16, 2024

With the latest master, this works for me,

import asyncio

from hypercorn.asyncio import serve
from hypercorn.config import Config
from quart import Quart, request, jsonify

app = Quart(__name__)


@app.route("/ping", methods=["GET"])
async def ping():
    return "pong"


config = Config()
config.bind = ["localhost:8080"]


async def main():
    finished = False

    async def foo():
        nonlocal finished
        await serve(app, config)
        finished = True

    asyncio.create_task(foo())
    while not finished:
        print("Hello")
        await asyncio.sleep(1)


asyncio.run(main())

With dbaf6a4, 354e7c8, and 19cbe37 being the crucial fixes.

from hypercorn.

Related Issues (20)

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.