Hi Everyone,
Asked this same question in r/flask as well
I am using apscheduler inside my flask application.
Note: I am not using Flask–APScheduler(flask extension). I am using its standalone library(pip install APScheduler)
========Let me give the context of my application ======================
i am starting my scheduler in create_app() function in application/__init__.py file. My code looks something like this
inside statusPollingScheduler.py file
def getStatusUpdatePollingScheduler(): executors={ 'default':ThreadPoolExecutor(1) } scheduler = BackgroundScheduler(executors=executors) scheduler.add_job( controllerThread, 'interval', seconds=15, max_instances=1, coalesce=True, args=(60,) #(timeout,) ) return scheduler
inside application/__init__.py file
def startPollingScheduler(): from .statusPollingScheduler import getStatusUpdatePollingScheduler sch=getStatusUpdatePollingScheduler() try: sch.start() applogger.info("Polling scheduler started at flask instance initiation") except Exception as e: applogger.error(f"Polling scheduler failed to start. Exception - {e}") def create_app(): app=Flask(__name__) applogger.info("Flask instance initiated") startPollingScheduler() return app
FYI i am running the flask with below code in main.py outside the application module
from application import create_app app=create_app() if __name__=='__main__': app.run()
=================MY ISSUE ===================
When I check the logs I see that Flask instance initiated and Polling scheduler started at flask instance initiation getting logged multiple times. Seems like my flask instance is getting restarted again and again as long as the apscheduler process is running. Now this is only happenning when I bring APscheduler in the picture. When I comment out the startPollingScheduler() function, flask does not get restarted repeateadly. I want to know the reason behind this.
Thanks
submitted by /u/deepbuzz7
[link] [comments]
r/learnpython Hi Everyone, Asked this same question in r/flask as well I am using apscheduler inside my flask application. Note: I am not using Flask-APScheduler(flask extension). I am using its standalone library(pip install APScheduler) ========Let me give the context of my application ====================== i am starting my scheduler in create_app() function in application/__init__.py file. My code looks something like this inside statusPollingScheduler.py file def getStatusUpdatePollingScheduler(): executors={ ‘default’:ThreadPoolExecutor(1) } scheduler = BackgroundScheduler(executors=executors) scheduler.add_job( controllerThread, ‘interval’, seconds=15, max_instances=1, coalesce=True, args=(60,) #(timeout,) ) return scheduler inside application/__init__.py file def startPollingScheduler(): from .statusPollingScheduler import getStatusUpdatePollingScheduler sch=getStatusUpdatePollingScheduler() try: sch.start() applogger.info(“Polling scheduler started at flask instance initiation”) except Exception as e: applogger.error(f”Polling scheduler failed to start. Exception – {e}”) def create_app(): app=Flask(__name__) applogger.info(“Flask instance initiated”) startPollingScheduler() return app FYI i am running the flask with below code in main.py outside the application module from application import create_app app=create_app() if __name__==’__main__’: app.run() =================MY ISSUE =================== When I check the logs I see that Flask instance initiated and Polling scheduler started at flask instance initiation getting logged multiple times. Seems like my flask instance is getting restarted again and again as long as the apscheduler process is running. Now this is only happenning when I bring APscheduler in the picture. When I comment out the startPollingScheduler() function, flask does not get restarted repeateadly. I want to know the reason behind this. Thanks submitted by /u/deepbuzz7 [link] [comments]
Hi Everyone,
Asked this same question in r/flask as well
I am using apscheduler inside my flask application.
Note: I am not using Flask–APScheduler(flask extension). I am using its standalone library(pip install APScheduler)
========Let me give the context of my application ======================
i am starting my scheduler in create_app() function in application/__init__.py file. My code looks something like this
inside statusPollingScheduler.py file
def getStatusUpdatePollingScheduler(): executors={ 'default':ThreadPoolExecutor(1) } scheduler = BackgroundScheduler(executors=executors) scheduler.add_job( controllerThread, 'interval', seconds=15, max_instances=1, coalesce=True, args=(60,) #(timeout,) ) return scheduler
inside application/__init__.py file
def startPollingScheduler(): from .statusPollingScheduler import getStatusUpdatePollingScheduler sch=getStatusUpdatePollingScheduler() try: sch.start() applogger.info("Polling scheduler started at flask instance initiation") except Exception as e: applogger.error(f"Polling scheduler failed to start. Exception - {e}") def create_app(): app=Flask(__name__) applogger.info("Flask instance initiated") startPollingScheduler() return app
FYI i am running the flask with below code in main.py outside the application module
from application import create_app app=create_app() if __name__=='__main__': app.run()
=================MY ISSUE ===================
When I check the logs I see that Flask instance initiated and Polling scheduler started at flask instance initiation getting logged multiple times. Seems like my flask instance is getting restarted again and again as long as the apscheduler process is running. Now this is only happenning when I bring APscheduler in the picture. When I comment out the startPollingScheduler() function, flask does not get restarted repeateadly. I want to know the reason behind this.
Thanks
submitted by /u/deepbuzz7
[link] [comments]