错误传输在使用Django通过Apache在Web上部署matlab应用程序时停止

时间:2016-08-09 01:00:14

标签: python django matlab

我有一个Matlab模拟器,因为我使用了Matlab Engine,所以我想创建一个Web应用程序。我可以在开发人员模式下使用Django来运行我的Matlab模拟器,但是当我尝试在发布者模式下通过Apache运行它时,它会向我显示一个错误,它对我没有意义,因为它在开发人员模式下运行良好而没有任何警告和错误。我带了一个显示错误的图像。

这是来自apache的error.log中的错误:

Traceback (most recent call last):
  File "/home/bsonlab/myproject/pytom.py", line 46, in <module>
    main(sys.argv[1:])
  File "/home/bsonlab/myproject/pytom.py", line 29, in main
    eng = matlab.engine.start_matlab()
  File "/usr/local/lib/python2.7/dist-packages/matlab/engine/__init__.py", line 112, in start_matlab
    eng = future.result()
  File "/usr/local/lib/python2.7/dist-packages/matlab/engine/futureresult.py", line 68, in result
    return self.__future.result(timeout)
  File "/usr/local/lib/python2.7/dist-packages/matlab/engine/matlabfuture.py", line 87, in result
    handle = pythonengine.getMATLAB(self._future)
matlab.engine.EngineError: Transport stopped.

这是我在view.py中的代码和调用Matlab Engine的文件:

#view.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.urlresolvers import reverse
from CRAN.forms import *
from django.contrib import auth
from django.template.context_processors import csrf
import os




def index(request):
    return render(request, 'CRAN/index.html')

def bigdata(request):
    return render(request, 'CRAN/bigdata.html')

def summer16(request):
    return render(request, 'CRAN/summer16.html')

def cran(request):
    return render(request, 'CRAN/cran.html')

def qson(request):
    return render(request, 'CRAN/qson.html')

def mobility(request):
    return render(request, 'CRAN/mobility.html')

def simulator(request):
    if request.method == 'POST':
        form = Output(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

        input1 = cd['User_Density']
        input2 = cd['RRH_Density']
        input3 = cd['Path_Loss_Exponent']
        input4 = cd['SIR_Threshold']
        input5 = cd['Outage_Capacity']
        input6 = cd['NBS_Bargaining']
        cmd = "/usr/bin/python /home/bsonlab/myproject/pytom.py --input1 %s --input2 %s --input3 %s --input4 %s --input5 %s --input6 %s" % (input1, input2, input3, input4, input5, input6)
        os.system(cmd)
        return render(request, 'CRAN/simulatorsecond.html', {'form': form})
    else:
        form = Output()
        return render(request, 'CRAN/simulator.html', {'form': form})

def simulatorsecond(request):
    if request.method == 'POST':
        form = Output(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

        input1 = cd['User_Density']
        input2 = cd['RRH_Density']
        input3 = cd['Path_Loss_Exponent']
        input4 = cd['SIR_Threshold']
        input5 = cd['Outage_Capacity']
        input6 = cd['NBS_Bargaining']
        cmd = "/usr/bin/python /home/bsonlab/myproject/pytom.py --input1 %s --input2 %s --input3 %s --input4 %s --input5 %s --input6 %s" % (input1, input2, input3, input4, input5, input6)
        os.system(cmd)
        return render(request, 'CRAN/simulatorsecond.html', {'form': form})

    else:
        form = Output()
        return render(request, 'CRAN/simulatorsecond.html', {'form': form})

和我正在调用matlab引擎的文件:

#pytom.py
import matlab.engine
import sys, getopt

def main(argv):
    print argv
    input1 = input2 = input3 = input4 = input5 = input0 = 0.0
    input1 = float(argv[1])
    input1 = input1/73850
    input2 = float(argv[3])
    input2 = input2/73850
    input3 = float(argv[5])
    input4 = float(argv[7])
    input5 = float(argv[9])
    input6 = float(argv[11])

    print((input1, input2, input3, input4, input5, input6))
    eng = matlab.engine.start_matlab()
    eng.user_centric_CRAN_web_function(input1, input2, input3, input4, input5, input6)

#input1-6 are 0.0003385240352,0.0002031144211,4,0.2,2.5,0.6



if __name__ == "__main__":
    main(sys.argv[1:])

user_centric_CRAN_web_function 是一个matlab函数,我在matlab中编写,它位于同一个文件夹中。

1 个答案:

答案 0 :(得分:1)

根据您的发行版,Web服务器用户(apache,www-data,?)可能已被锁定,无法写入其$ HOME。在Redhat / CentOS上,apache用户$ HOME是/ usr / share / httpd /。当Matlab以该用户身份启动时,进程字符串中的某些内容将尝试创建$ HOME / .config或其他特定于用户的文件,并且Matlab会在信息性传输停止的情况下死亡。&#34;试试这个:

chown apache:apache /usr/share/httpd/

或您系统上的等效文件。可以使用&#34; getent passwd $ USER&#34;找到用户$ HOME目录,$ HOME是第6个:分隔字段。

如果不是这样,那么找一些Matlab希望能够在启动时做的事情,哪些权限会​​阻止作为网络服务器用户。

免责声明:我不知道进行此更改的安全隐患是什么。