Comments (12)
Usually I create two files, one to run locally and another one for uwsgi/gunicorn/apache.
e.g:
# myapp.py
# my app logic goes here
def create_app():
return Flask(__name__)
# run.py
# used to run locally
from myapp import create_app
if __name__ == '__main__':
manager = Manager(create_app())
manager.run()
# wsgi.py
# used to run on uwsgi/apache
from myapp import create_app
application = create_app()
from flask-apscheduler.
Can you provide an example of what you are trying to accomplish?
from flask-apscheduler.
I am trying to make a set of functions so that it can change the values in redis_db
from flask-apscheduler.
I can't help you without an example, can you post here how you are initializing Flask and APSchduler?
from flask-apscheduler.
I am using flask manager for developement server and apache2 for production server.
Below is the code for manag.py:
import os
from app import create_app, db
from app.models import User, Order, Contact, Wallet, Withdraw, Deposit, Transaction, Subscription
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
def make_shell_context():
return dict(app=app, db=db, User=User)
app = create_app('development')
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
if name == 'main':
scheduler.start()
manager.run()
Below is the code for intit.py:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy # using orm wrapper around sqlalchemy
from flask_login import LoginManager # for login sessions
from . import config # config file having different configurations
import redis
from flask_apscheduler import APScheduler
db = SQLAlchemy()
redis_db = redis.StrictRedis(host='localhost', port=6379, db=0)
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'auth.login' # Default login page, after any bad requests
scheduler = APScheduler()
import app.models
def create_app(config_name):
app = Flask(name)
app.config.from_object(config.config[config_name])
config.config[config_name].init_app(app)
login_manager.init_app(app)
db.init_app(app)
scheduler.init_app(app)
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
# attach routes and custom error pages herereturn app
return app
app = create_app('development')
from flask-apscheduler.
Where do you start APScheduler?
The only place I see it in your code is here:
if name == 'main':
scheduler.start()
manager.run()
But I think this code above isn't being executed with Apache2.
I would suggest you to start APScheduler within create_app
:
def create_app(config_name):
....
scheduler.start()
I hope it helps you out
from flask-apscheduler.
I have not tested it on apache2, I was thinking first to test it on local flask server, that is why I had placed scheduler.start in the manager. If I put it inside the create_app then it returns that the schedular is already running. But with schedular.start() inside the manager, it gives the error that the job is already running
from flask-apscheduler.
Just for testing, I've built this example similar to yours, it works well.
from flask import Flask
from flask_apscheduler import APScheduler
from flask_script import Manager, Shell
scheduler = APScheduler()
def create_app():
app = Flask(__name__)
scheduler.init_app(app)
scheduler.start()
return app
def make_shell_context():
return dict(app=app)
app = create_app()
manager = Manager(app)
manager.add_command("shell", Shell(make_context=make_shell_context))
if __name__ == '__main__':
manager.run()
python main.py runserver
Try to run it and see what happens.
from flask-apscheduler.
Can it be that I am using different files for manager and init, it is happening
from flask-apscheduler.
That makes no difference.
Before you got scheduler is already running because you are calling twice create_app('development')
from flask-apscheduler.
creat_app('development') is for apache. Can you suggest any configuration that can work with both apache and flask?
from flask-apscheduler.
thanks for all the help
from flask-apscheduler.
Related Issues (20)
- `scheduler.resume_job` failed to work
- Question about use the gunicorn to deploy flask-apsscheduler? HOT 1
- [PLS HELP] Flask-Appbuilder - accessing scheduler from views.py HOT 2
- ModuleNotFoundError: No module named 'scheduler' HOT 2
- The task is interrupted inexplicably
- Trying to run a function as a schedule and also trigger on demand HOT 4
- Flask-APScheduler not running when set some environment variables HOT 3
- Running job causes detachedinstanceerror HOT 3
- Use Codecov in informational mode HOT 1
- APScheduler not working with gunicorn eventlet HOT 6
- Flask 2.3.2 causing KeyError: 'JSONIFY_PRETTYPRINT_REGULAR' HOT 1
- Flask-APScheduler multiple jobs running at the same time when having multiple workers HOT 1
- [RFE] Package python3-flask-apscheduler into RPM
- KeyError: 'JSONIFY_PRETTYPRINT_REGULAR' when running Flask as a development server HOT 2
- Apscheduler not working with flask debug=True & --no-reload
- Flask 3.0.0 support HOT 1
- Behaviour of processpool HOT 1
- Key Error while passing redis instance as arg HOT 2
- Can't start BlockingScheduler as daemon in debug mode
- Issue with sqlalchemy (cannot join current thread and working outside of app context) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-apscheduler.