猿问

【python新人求助】flask+pymssql 通过wsgi发布到Apache,访问接口服务器卡死?

前端发起http请求 '/getData' ,项目就卡死

index.py 代码如下:

from flask import Flask,render_template,request
import json
import pymssql
import urllib.parse
import sys
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')
@app.route('/hello')
def hello():
    return 'hello world'
@app.route('/getData',methods=['GET'])
def getddlData(): 
    # return json.dumps([])
    sql='SELECT DISTINCT ChatRoomName FROM dbo.Issue'
    conn=pymssql.connect(host="localhost", user="sa", password="123456", database="IssueCollect") 
    cursor=conn.cursor(as_dict=True) 
    cursor.execute(sql)
    rooms=cursor.fetchall()
    cursor.close()
    conn.close()
    return json.dumps(rooms) 
if __name__ == '__main__':
    app.run()

test.wsgi:

import sys
#app's path
sys.path.insert(0,"C:/Users/Stephen/Desktop/IssueCollect")
from index import app
#Initialize WSGI app object
application = app

Apache conf

LoadFile "c:/program files (x86)/python37-32/python37.dll"
LoadModule wsgi_module "c:/program files (x86)/python37-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd"
WSGIPythonHome "c:/program files (x86)/python37-32"

<VirtualHost *:5001>
    WSGIScriptAlias / C:/Users/Stephen/Desktop/IssueCollect/test.wsgi
    <Directory C:/Users/Stephen/Desktop/IssueCollect>
        Require all granted
    </Directory>
</VirtualHost>

卡死后关闭httpd,查看Apache error log:

on Jul 23 14:05:52.534352 2018] [mpm_winnt:notice] [pid 3856:tid 600] AH00455: Apache/2.4.34 (Win32) mod_wsgi/4.6.4 Python/3.7 configured -- resuming normal operations
[Mon Jul 23 14:05:52.534853 2018] [mpm_winnt:notice] [pid 3856:tid 600] AH00456: Server built: Jul 10 2018 09:24:15
[Mon Jul 23 14:05:52.534853 2018] [core:notice] [pid 3856:tid 600] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Mon Jul 23 14:05:52.536599 2018] [mpm_winnt:notice] [pid 3856:tid 600] AH00418: Parent: Created child process 18044
Apache server shutdown initiated...
pm_winnt:notice] [pid 18044:tid 712] AH00354: Child: Starting 512 worker threads.
[Mon Jul 23 14:06:58.522281 2018] [mpm_winnt:notice] [pid 3856:tid 600] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Mon Jul 23 14:07:30.572310 2018] [mpm_winnt:notice] [pid 18044:tid 712] AH00362: Child: Waiting 30 more seconds for 2 worker threads to finish.
[Mon Jul 23 14:08:00.692059 2018] [mpm_winnt:notice] [pid 18044:tid 712] AH00362: Child: Waiting 0 more seconds for 2 worker threads to finish.
[Mon Jul 23 14:08:00.792357 2018] [mpm_winnt:notice] [pid 18044:tid 712] AH00363: Child: Terminating 2 threads that failed to exit.
[Mon Jul 23 14:08:00.792357 2018] [mpm_winnt:notice] [pid 18044:tid 712] AH00364: Child: All worker threads have exited.

在本地python中执行index.py访问正常,
发布到Apache服务器上,不连接数据库直接返回空正常。
连接数据库就有问题。
是我Apache配置问题吗?

侃侃无极
浏览 988回答 2
2回答

GCT1015

放弃Apache,转nginx+uwsgi解决问题

缥缈止盈

检查 SQL SELECT DISTINCT ChatRoomName FROM dbo.Issue 的结果集是否太大。
随时随地看视频慕课网APP

相关分类

Python
我要回答