-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduler does not start with Gunicorn in v1.12.3 #198
Comments
Any chance you can share your wsgi and init files for your app? |
I guess, though I would be surprised if it gives you any insight deeper than what is above # __init__.py
import logging
import os
from typing import (
Optional,
)
from flask import (
Flask,
request,
)
from backend.routes import root
from backend.extensions import (
db,
migrate,
cron,
)
from backend.utils import (
configure_logger,
do_task,
)
def create_app(config_object_path: Optional[str] = None) -> Flask:
'''
Flask app factory function. Creates and initializes the app.
Args:
config_object_path: an optional string defining the path of the
configuration object
Returns:
A configured Flask app
'''
app = Flask(__name__)
if config_object_path is None:
app.config.from_object('backend.config.EnvironmentConfiguration') # type: ignore
else:
app.config.from_object(config_object_path)
configure_logger(app.logger, debug=app.config['ENV'] == 'development')
return initialize_app(app)
def initialize_app(app: Flask) -> Flask:
'''
Sets up all the applicable extensions and routes from blueprints
Args:
app: A pre-configured application object
Returns:
The same object, after all routes and initializations
'''
app.register_blueprint(root)
db.init_app(app)
migrate.init_app(app, db)
cron.init_app(app)
@app.before_request
def _():
app.logger.info(
'Hit route path %s',
request.path
)
@cron.task('interval', id='task', minutes=10, misfire_grace_time=900)
def _():
with app.app_context():
do_task()
cron.start()
return app # wsgi.py
from backend import create_app
app = create_app() |
Hmm I use gunicorn as well and haven't had that problem. The only difference in my startup is that I put my Here's how I call gunicorn.
|
Is it potentially due to not using reload that you don't experience this issue? Again, I do think it's just due to that change in #140 - It silently causes the scheduler to not start if the process is the reloader (but isn't documented), which is exactly the use case that I'm trying to do. |
On some further inspection, I think #163 might be connected to this issue as well: the user who reported it seems to likewise be utilizing the reloader thread |
Ah yep I'm sure you are correct.
Feb 22, 2022, 8:28 PM by ***@***.***:
…
On some further inspection, I think > #163 <#163>> might be connected to this issue as well: the user who reported it seems to likewise be utilizing the reloader thread
—
Reply to this email directly, > view it on GitHub <#198 (comment)>> , or > unsubscribe <https://github.com/notifications/unsubscribe-auth/AEHW6IQOXGBEZD25D4ISFJLU4RA3ZANCNFSM5OYMROGQ>> .
Triage notifications on the go with GitHub Mobile for > iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>> or > Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>> .
You are receiving this because you commented.> Message ID: > <viniciuschiele/flask-apscheduler/issues/198/1048396283> @> github> .> com>
|
Decided to play around a little bit with this, so I wrote a test app to reproduce the issue: https://github.com/taliamax/flask-test On further inspection, I think I was very wrong about the actual cause, though correct about the location. The offending line seems to be
The problem seems to be that FLASK_ENV is set to A potential fix might be to either:
|
This is the expected behavior of the scheduler > using debug + a non debug server will prevent the scheduler from running. See #220 (comment) for more information. |
It seems incredibly strange to me that the guidance offered here is "use only a specific server". Is there really no room to even enable a configuration flag for bypassing that? |
Because there is no reliable way to detect if Thoughts? cc: @Gkirito |
Good idea! |
In case you found this by googling: You can fix this by downgrading to 1.12.1
I have been running into the issue wherein if I use the Flask development server with
flask run
, the scheduler will start, but by runninggunicorn
it did not. I tried adding the job (with no persistent memory store) in thecreate_app
function, pre-loading, not-pre-loading, adding the tasks in the@app.before_first_request
decorated function, and even starting the scheduler 3 separate times in my code (once increate_app
, once in thebefore_first_request
, and once in awsgi.py
file). In all cases, querying the/scheduler
api always returned arunning=false
state.Here's the command I used to start gunicorn:
environment configs:
Using docker image
python:3.9-slim-buster
, running Python 3.9.10I've spent a few hours slamming my head against a wall on this one, and I think it comes down to the PR #140 that resolved #139. I'd probably recommend adding something like a
SCHEDULER_ALLOW_RELOADER
environment variable to bypass it, and specifying it in the documentation.The text was updated successfully, but these errors were encountered: