I am trying to launch a Flask App on AWS EC2 and I am trying to use flask-apscheduler
to enable background threading. However, when importing the library, my code breaks.
/etc/httpd/logs/error_log:
mod_wsgi (pid=29266): Target WSGI script '/var/www/html/flaskapp/flaskapp.wsgi' cannot be loaded as Python module., referer: http:/$
mod_wsgi (pid=29266): Exception occurred processing WSGI script '/var/www/html/flaskapp/flaskapp.wsgi'., referer: http:/$
Traceback (most recent call last):, referer: http://example.com/map-day
File "/var/www/html/flaskapp/flaskapp.wsgi", line 6, in <module>, referer: http://example.com/map-day
from flaskapp import app as application, referer: http://example.com/map-day
File "/var/www/html/flaskapp/flaskapp.py", line 3, in <module>, referer: http://example.com/map-day
from flask_apscheduler import APScheduler, referer: http://example.com/map-day
File "/usr/local/lib/python2.7/site-packages/flask_apscheduler/__init__.py", line 17, in <module>, referer: http://example.com$
from apscheduler.schedulers.base import STATE_PAUSED, STATE_RUNNING, STATE_STOPPED, referer: http://example.com/map-day
File "/usr/local/lib64/python2.7/site-packages/apscheduler/schedulers/base.py", line 19, in <module>, referer: http:/$
from apscheduler.jobstores.memory import MemoryJobStore, referer: http://example.com/map-day
File "/usr/local/lib64/python2.7/site-packages/apscheduler/jobstores/memory.py", line 4, in <module>, referer: http:/$
from apscheduler.util import datetime_to_utc_timestamp, referer: http://example.com/map-day
File "/usr/local/lib64/python2.7/site-packages/apscheduler/util.py", line 141, referer: http://example.com/map-day
values = {k: int(v or 0) for k, v in values.items()}, referer: http://example.com/map-day
^, referer: http://example.com/map-day
SyntaxError: invalid syntax, referer: http://example.com/map-day
A quick search on the Internet reveals few results of similar problems and are experienced by users using Python 2.6 while importing other libraries. These users were recommended to upgrade to Python 2.7 and their issue seemed to be resolved by doing so thereafter.
I am, however, using Python 2.7.14 and Flask-APScheduler 1.10.1. While I can surely use another library to do background threading, I am curious to find out if I am missing something - the issue was with dictionary comprehension that cannot be done using Python 2.6, yet I am experiencing the same issue using 2.7. Am I missing something?
After diving further, I found out that specifying the python version in my flask wsgi configuration does not affect which python is used to execute my flask app.
Running this gives the system default for my RHEL VM which is Python 2.6:
$ which python
/usr/bin/python
While I can change the python default version or create a venv and specify the python to be used, I have switched to another distribution using Python 2.7 as the system default due to this among other reasons. Hope this will help anyone who are experiencing a similar problem.