问题
I am permit you to ask you about a problem that I have with hosting flask application with your portage of mod_wsgi on windows
I have two flask application and only one can be alive a the same times due to conflict in import
ie : If a request application 1 I have a response Then if I request application 2 I have internal server error with error in log ... Then if I restart apache and I request application 2 I have a response but if I request application 1 I have the same internal server error If I comments some import like numpy both application can be alive at the same time
Any help would be appreciated if you have any idea or link or answer to about this problem?
My installation is describe below
Thanks by advance for tour times and your works
Alexandre
LOG of the error
mod_wsgi (pid=4936): Failed to exec Python script file 'D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi'.
mod_wsgi (pid=4936): Exception occurred processing WSGI script 'D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi'.
Traceback (most recent call last):
File "D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi", line 3, in
from api_test_2 import app as application
File "D:/exec/wsgi_api/api_test_2\api_test_2.py", line 2, in
import numpy
File "c:\python\python36\lib\site-packages\numpy\__init__.py", line 142, in
from . import core
File "c:\python\python36\lib\site-packages\numpy\core\__init__.py", line 16, in
from . import multiarray
File "c:\python\python36\lib\site-packages\numpy\core\multiarray.py", line 12, in
from . import overrides
File "c:\python\python36\lib\site-packages\numpy\core\overrides.py", line 46, in
""")
RuntimeError: implement_array_function method already has a docstring
#---------------------------------
# file : D:/exec/wsgi_api/api_test_1/api_test_1.py
#---------------------------------
from flask import Flask, jsonify,render_template, request, make_response
import numpy
app = Flask(__name__)
@app.route('/')
def home():
resp = make_response("hello from 1", 200)
resp.headers['Content-Type'] = 'charset=utf-8'
return resp
#---------------------------------
#---------------------------------
# file : D:/exec/wsgi_api/api_test_2/api_test_2.py
#---------------------------------
from flask import Flask, jsonify,render_template, request, make_response
import numpy
app = Flask(__name__)
@app.route('/')
def home():
resp = make_response("hello from 2", 200)
resp.headers['Content-Type'] = 'charset=utf-8'
return resp
if __name__ == '__main__':
app.run(host='127.0.0.1', port=36000)
#---------------------------------
I have this two wsgi file in appache httpdocs
#---------------------------------
# file : D:/exec/Apache24/htdocs/wsgi/api_test_1.wsgi
#---------------------------------
import sys
sys.path.append('D:/exec/wsgi_api/api_test_1/')
from api_test_1 import app as application
#---------------------------------
#---------------------------------
# file : D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi
#---------------------------------
import sys
sys.path.append('D:/exec/wsgi_api/api_test_1/')
from api_test_1 import app as application
#---------------------------------
#---------------------------------
In D:/exec/Apache24/conf/httpd.conf i add the line
#---------------------------------
WSGIScriptAlias /api_test_1 "D:/exec/Apache24/htdocs/wsgi/api_test_1.wsgi"
WSGIScriptAlias /api_test_2 "D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi"
#---------------------------------
回答1:
I had a similar issue in a project. In my case, I had to add WSGIApplicationGroup %{GLOBAL}
inside the .conf
file of my site.
This is the documentation where I found the information:
https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#sub-interpreter-being-used
回答2:
Thanks for your response it works.
I had a discussion on the mod_wsgi mailing list and I had the same response The explanation is numpy doesn't work in Python sub interpreters as the C extension modules are not implement properly to allow that, thus for mod_wsgi you can only use numpy in the main interpreter context, forced by the 'WSGIApplicationGroup %{GLOBAL}' directive
This is linked with the subject https://github.com/numpy/numpy/issues/3961
So thanks to all people who helped me especially Cody Gray and Graham Dumpleton
Kind Regards
Alx
回答3:
Try putting this in your WSGI configuration file:
single-interpreter = true
来源:https://stackoverflow.com/questions/54537814/import-conflict-when-running-flask-app-with-apache-mod-wsgi-on-windows