Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Jorge Escobar
    @esfoobar
    However that conn2 object is different from the engine.acquire() here: https://github.com/esfoobar/quart-feed/blob/master/db.py#L14
    Do you know of a snippet that has a pool that's compatible with SqlAlchemy?
    Jorge Escobar
    @esfoobar
    I'm using SQLAlchemy Core so that pool implementation doesn't work
    Tigran Tch
    @NargiT

    The ASGI root_path should work for this, could you try with hypercorn and see if it narrows down the bug to uvicorn or Quart?

    root_path does not add in the url the path. Do I have to setup a proxy and rewrite url in order to redirect to "/" ?

    Phil Jones
    @pgjones
    This may be a bug, I'll try find some time to investigate
    @esfoobar have you tried using Databases?
    Jorge Escobar
    @esfoobar
    I have read about it -- I can try implementing -- I just wish I knew it was going to fix the issue
    But I appreciate your help @pgjones
    Phil Jones
    @pgjones
    I use it, and it seems to setup connection pools
    Jorge Escobar
    @esfoobar
    Awesome, I'll see if I can hook it up quickly and will let you know
    Phil Jones
    @pgjones
    @NargiT I think ASGI servers have a bug, django/asgiref#229
    Jorge Escobar
    @esfoobar
    @pgjones I'm SO HAPPY! The move to databases made all the difference. It's now rock solid, reloading as fast I can throws no errors!
    And the SSE experience feels near-instantaneous, thanks!
    Phil Jones
    @pgjones
    :+1:
    Nice
    Phil Jones
    @pgjones
    @NargiT The Hypercorn master branch should work as you expect with the root-path if you can try it out
    Jorge Escobar
    @esfoobar

    Hi @pgjones , I am now seeing a new error on tests that I hadn't seen before.

    In my conftest I have the following fixture:

    @pytest.fixture(scope="module")
    async def create_test_app(create_db):
        app = create_app(**create_db)
        await app.startup()
        yield app
        await app.shutdown()

    It seems app.shutdown() is throwing this error:

    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
        raise value
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
        raise value
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:93: in finalizer
        loop.run_until_complete(async_finalizer())
    /usr/local/lib/python3.8/asyncio/base_events.py:616: in run_until_complete
        return future.result()
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:85: in async_finalizer
        await gen_obj.__anext__()
    conftest.py:67: in create_test_app
        await app.shutdown()
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
    self = <quart.app.Quart object at 0x7f9947998dc0>
    
        async def shutdown(self) -> None:
            for func in self.after_serving_funcs:
                await func()
            app_ctx = _app_ctx_stack.top
    >       await app_ctx.pop(None)
    
    /root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/quart/app.py:2155: AttributeError
    ================================================================ short test summary info =================================================================
    ERROR relationship/test_relationship.py::test_succesful_follow - AttributeError: 'NoneType' object has no attribute 'pop'
    ERROR user/test_user.py::test_profile_edit - AttributeError: 'NoneType' object has no attribute 'pop'

    Any ideas what is going on?

    I'm using:

    pytest = "==6.2.1"
    pytest-asyncio = "==0.14.0"
    On the application.py I have these:
        @app.before_serving
        async def create_db_conn():
            database = await db_connection()
            await database.connect()
            app.dbc = database
    
        @app.after_serving
        async def close_db_conn():
            await app.dbc.disconnect()
    Phil Jones
    @pgjones
    It should work again if you use master, or if you utilise the test_app
    Jorge Escobar
    @esfoobar

    That worked, but now I have an issue with context?

    I have on the tests:

        # check that the user was created on the database itself
        async with create_test_app.app_context():

    and I'm getting:

    E       AttributeError: 'TestApp' object has no attribute 'app_context'
    Phil Jones
    @pgjones
    You can still yield the app, just within the test_app context,
    @pytest.fixture(scope="module")
    async def create_test_app(create_db):
        app = create_app(**create_db)
        async with app.test_app():
            yield app
    Jorge Escobar
    @esfoobar
    Amazing, that worked! Thanks!
    TheHolyRoger
    @TheHolyRoger
    @pgjones forgive my vagueness because I'm reporting an issue I had a while back now - I was trying to run quart in a separate thread but would always get the "signal only works in main thread" error - I think it's something to do with the autoloader, which I did disable without any success?
    Phil Jones
    @pgjones
    It is the usage of the shutdown_trigger that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your own shutdown_trigger and use the run_task method. The shutdown_trigger should be an awaitable that is done when you want the app to shutdown.
    sferdi0
    @sferdi0
    I've noticed that CTRL-C'ing hypercorn takes a second or two to quit, possibly related to some cleanup process... Can I somehow replace this with a SIGKILL, in favor of quickly being able to start/stop hypercorn?
    (For development purposes)
    sferdi0
    @sferdi0
    await asyncio.sleep(config.graceful_timeout)
    I FOUND YOU
    sferdi0
    @sferdi0
    Any side-effects with setting this to 0?
    Phil Jones
    @pgjones
    None
    This is on my todo list to improve, I need to somehow early exit if the relevant tasks have completed.
    McSinyx
    @McSinyx:matrix.org
    [m]
    in case hypercorn runs on trio, does nursery/cancel scope makes it any easier?
    Phil Jones
    @pgjones
    Hopefully, although I haven't got it right so far
    Vito De Tullio
    @ZeeD

    Hi.
    I've just updated quart, quart-trio and hypercorn and I'm having this mypy error:

    : error: Argument 1 to "serve" has incompatible type "QuartTrio"; expected "Union[Type[ASGI2Protocol], Callable[[Union[HTTPScope, WebsocketScope, LifespanScope], Callable[[], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebsocketConnectEvent, WebsocketReceiveEvent, WebsocketDisconnectEvent, LifespanStartupEvent, LifespanShutdownEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebsocketAcceptEvent, WebsocketSendEvent, WebsocketResponseStartEvent, WebsocketResponseBodyEvent, WebsocketCloseEvent, LifespanStartupCompleteEvent, LifespanStartupFailedEvent, LifespanShutdownCompleteEvent, LifespanShutdownFailedEvent]], Awaitable[None]]], Awaitable[None]]]"
    moves\web\__init__.py:85: error: Argument 1 to "serve" has incompatible type "QuartTrio"; expected "Union[Type[ASGI2Protocol], Callable[[Union[HTTPScope, WebsocketScope, LifespanScope], Callable[[], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebsocketConnectEvent, WebsocketReceiveEvent, WebsocketDisconnectEvent, LifespanStartupEvent, LifespanShutdownEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebsocketAcceptEvent, WebsocketSendEvent, WebsocketResponseStartEvent, WebsocketResponseBodyEvent, WebsocketCloseEvent, LifespanStartupCompleteEvent, LifespanStartupFailedEvent, LifespanShutdownCompleteEvent, LifespanShutdownFailedEvent]], Awaitable[None]]], Awaitable[None]]]"

    the "incriminated" line is await hypercorn.trio.serve(app, config), where I have

    app = cast(quart_trio.QuartTrio,
                   quart_cors.cors(quart_trio.QuartTrio(__name__),
                                   allow_origin='*',
                                   allow_methods=['POST'],
                                   allow_headers=['content-type']))
    Phil Jones
    @pgjones
    Best to ignore this at the moment, will be fixed in an upcoming release
    1 reply
    TheHolyRoger
    @TheHolyRoger

    It is the usage of the shutdown_trigger that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your own shutdown_trigger and use the run_task method. The shutdown_trigger should be an awaitable that is done when you want the app to shutdown.

    Thanks!

    paulinechane
    @PaulineChane

    It is the usage of the shutdown_trigger that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your own shutdown_trigger and use the run_task method. The shutdown_trigger should be an awaitable that is done when you want the app to shutdown.

    Thanks!

    hello! apologies for poorly phrased questions in advance, i am very new to python frameworks and asyncio!

    i am still having a hard time to get this to work -- trying to run a quart app to be used on a website along with bot that runs 24/7 on discord. my understanding is that this run_task() method would be run for the quart app?

    Baran Yildirim
    @baranyildirim
    Is it possible to make Quart work with React via templates? I would like to have a quart application where I use React components, but I do not want a single page application. I also don't want to run node and quart simultaneously.
    Phil Jones
    @pgjones
    Yes, you can just embed React as you need into the templates (via a script tag).
    I typically build a SPA and serve that with Quart
    Ernesto Ruge
    @the-infinity
    I usually use React + Quart or Fask partly jinja2-rendered, partly React-rendered. It works really fine (but Quart / Flask has not much to do with the React part, it just feeds it via API).
    It even works as a single page application including deeplinks and React Router if you set your endpoints in a correct way
    Phil Jones
    @pgjones
    @PaulineChane I'll try and write something up for this soon - short of time.
    Yes though, the run_task method would run the quart app.
    TheHolyRoger
    @TheHolyRoger
    hey @pgjones do you have plans to add "call_on_close" similar to flask to quart?
    Currently I'm using middleware around the asgi app, but it would be nice to have access to request variables within my called functions
    right now i'm manually parsing scope['query_string'] and the headers etc again myself
    Phil Jones
    @pgjones
    Could you spawn a background task for this?
    Do you need to guarantee the task doesn't start till the response has completed?