Skip to content
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

Flask-APScheduler not running when set some environment variables #220

Closed
GodsDusk opened this issue Mar 10, 2023 · 3 comments
Closed

Flask-APScheduler not running when set some environment variables #220

GodsDusk opened this issue Mar 10, 2023 · 3 comments

Comments

@GodsDusk
Copy link

set FLASK_ENV=development or FLASK_DEBUG any value

@christopherpickering
Copy link
Collaborator

@GodsDusk Can you share an example?

@GodsDusk
Copy link
Author

here is an example:

M1 Pro Ventura
python 3.10
Flask-APScheduler 1.12.4
Flask 2.2.2
gevent 22.10.2

# run.py
from flask import Flask
from flask_apscheduler import APScheduler

scheduler = APScheduler()


@scheduler.task("interval", id="job1", seconds=3, misfire_grace_time=900)
def job1():
    """Sample job 1."""
    print("Job 1 executed")


if __name__ == "__main__":
    app = Flask(__name__)

    scheduler.init_app(app)
    scheduler.start()

    from gevent.pywsgi import WSGIServer
    http_server = WSGIServer(('0.0.0.0', 5001), app)
    http_server.serve_forever()

first, I exec python run.py, It works fine, and "Job 1 executed" is printed on the console.

Then, I exec export FLASK_DEBUG=development && python run.py, nothing printed

@christopherpickering
Copy link
Collaborator

Well, in development you can use the flask dev server, using one of these excellent examples: https://github.com/viniciuschiele/flask-apscheduler/tree/master/examples

Using a production server + debug will prevent the scheduler from starting

if get_debug_flag() and not werkzeug.serving.is_running_from_reloader():

This was done to allow development to work with the flask debugger.

You could tweak your startup to look something like:

from flask.helpers import get_debug_flag
if get_debug_flag():
    app.run()
else:
    .... wsgi server run forever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants