Azure Flask Web App上的内部服务器错误

2024-04-27 18:53:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Dreamspark订阅在Azure上创建了一个Flask web应用程序。它使用诸如Numpy、Scipy和Theano等库。在

当我使用简单的Theano计算来部署应用程序时,它工作得非常完美。但是,当我将代码更改为更复杂的Theano计算时,我得到了一个内部服务器错误。在

下面是一个示例代码。当我调用simpleFunction(类似于求和的函数)时,它可以工作,但当调用complexFunction(类似于图像分类计算)时,它会创建一个内部服务器错误:

from flask import Flask
app = Flask(__name__)
wsgi_app = app.wsgi_app

from fileContainingTheanoCode import simpleFunction, complexFunction

@app.route('/')
def hello():
    result = simpleFunction()
    thisStr = str(result)
    return   """<html>
                    <head>
                        <title>Test website</title>
                    </head>
                    <body>
                        <h1>"""+thisStr+"""</h1>
                    </body>
                </html>"""


if __name__ == '__main__':
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    app.run(HOST, PORT)

为了清楚起见,下面是该文件的代码anocode.py(这是一个卷积神经网络分类器,加载模块用于从文件中读取mnist数据集):

^{pr2}$

下面是详细的错误消息:

Event: MODULE_SET_RESPONSE_ERROR_STATUS
ModuleName  FastCgiModule
Notification    EXECUTE_REQUEST_HANDLER
HttpStatus  500
HttpReason  INTERNAL SERVER ERROR
HttpSubStatus   0
ErrorCode   The operation completed successfully.
 (0x0)

下面是事件日志:

</Data></EventData></Event><Event><System><Provider Name="ASP.NET 4.0.30319.0"/><EventID>1325</EventID><Level>3</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2016-06-05T19:34:20Z"/><EventRecordID>1604538437</EventRecordID><Channel>Application</Channel><Computer>RD000D3A218E0C</Computer><Security/></System><EventData><Data>An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/1568611192/ROOT

Process ID: 647864

Exception: System.Configuration.ConfigurationErrorsException

Message: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

StackTrace:    at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData)
   at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
   at System.Diagnostics.ListenerElement.GetRuntimeObject()
   at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
   at System.Diagnostics.TraceInternal.get_Listeners()
   at System.Diagnostics.TraceInternal.WriteLine(String message)
   at System.Diagnostics.Debug.WriteLine(String message)
   at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(Object stateInfo)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()</Data></EventData></Event><Event><System><Provider Name=".NET Runtime"/><EventID>1026</EventID><Level>0</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2016-06-05T19:34:20Z"/><EventRecordID>1604538453</EventRecordID><Channel>Application</Channel><Computer>RD000D3A218E0C</Computer><Security/></System><EventData><Data>Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException
   at System.Diagnostics.TraceUtils.GetRuntimeObject(System.String, System.Type, System.String)
   at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
   at System.Diagnostics.ListenerElement.GetRuntimeObject()
   at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
   at System.Diagnostics.TraceInternal.get_Listeners()
   at System.Diagnostics.TraceInternal.WriteLine(System.String)
   at System.Diagnostics.Debug.WriteLine(System.String)
   at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(System.Object)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()

</Data></EventData></Event></Events>

Tags: eventappdatagetstringobjectsystemat
1条回答
网友
1楼 · 发布于 2024-04-27 18:53:05

造成这个问题的原因有很多,比如多线程、使用gpu、内存限制等等,但是根据代码和错误信息,我不能确定是什么原因。在

我建议您可以尝试参考theano文档“Debugging Theano: FAQ and Troubleshooting”和文章“Azure Web App sandbox”,以找出真正由什么引起的问题。在

你能分享complexFunction的代码吗?我认为这对分析问题很有帮助,甚至尝试复制它来找出解决方案。在


更新

根据您的代码和事件日志,我认为有两个可能的原因导致了这个问题。在

  1. 一些代码逻辑错误导致了服务器内部错误,但是如果代码在本地运行良好,请忽略这种可能性。

  2. 您的webapp配置不正确,如web.config,请参阅^{}部分以检查其配置是否正确。

相关问题 更多 >