librelist archives

« back to archive

@app.before_first_request

@app.before_first_request

From:
Erik Forsberg
Date:
2015-05-06 @ 08:30
Hi!

I have a function decorated with @app.before_first_request. It
configures our (global) database connection and prepared some queries on
it. This takes a couple of seconds, and happens when I make the first
request after server start.

If a second request comes in while the database query prepare process is
running, I'm getting errors related to my database queries not being
prepared. So it seems like the @app.before_first_request the first
request triggered does not block the second request from being handled.

What am I doing wrong here? Or have I misunderstood how the
@app.before_first_request decorator works?

Flask 0.10.1. I run with Apache and the following configuration
(basically copied from
http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/):

    WSGIDaemonProcess name processes=1 threads=15
    WSGIScriptAlias / /path/ospapi.wsgi
    WSGIScriptReloading On

    <Directory /path>
        WSGIProcessGroup name
        WSGIApplicationGroup %{GLOBAL}
    </Directory>

Thanks,
\EF

Re: [flask] @app.before_first_request

From:
Dorian Hoxha
Date:
2015-05-07 @ 11:42
Can you reproduce this with the builtin flask server ?
Can you tell what you're exactly doing on the @befre_first_request ?
Can you tell the exact error?
Can you simplify your code so that the code is shorter and the error
remains so we can look and test?


On Wed, May 6, 2015 at 10:30 AM, Erik Forsberg <forsberg@opera.com> wrote:

> Hi!
>
> I have a function decorated with @app.before_first_request. It
> configures our (global) database connection and prepared some queries on
> it. This takes a couple of seconds, and happens when I make the first
> request after server start.
>
> If a second request comes in while the database query prepare process is
> running, I'm getting errors related to my database queries not being
> prepared. So it seems like the @app.before_first_request the first
> request triggered does not block the second request from being handled.
>
> What am I doing wrong here? Or have I misunderstood how the
> @app.before_first_request decorator works?
>
> Flask 0.10.1. I run with Apache and the following configuration
> (basically copied from
> http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/):
>
>     WSGIDaemonProcess name processes=1 threads=15
>     WSGIScriptAlias / /path/ospapi.wsgi
>     WSGIScriptReloading On
>
>     <Directory /path>
>         WSGIProcessGroup name
>         WSGIApplicationGroup %{GLOBAL}
>     </Directory>
>
> Thanks,
> \EF
>