Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Transport Stopped when deploying matlab app on the web using Django through Apache

I have a Matlab simulator and I want to make a web application since I used Matlab Engine. I can run my Matlab simulator by using Django in developer mode, but when I try to run it through Apache on publisher mode, it shows me an error and it does not make sense for me because it is working well on developer mode without any warning and error. I bring an image which shows the error.

This is error in error.log from apache:

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.

and here is my code in view.py and file which is calling 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})

and file which I am calling matlab engine:

#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 is a matlab function which I wrote in matlab and it is in same folder.

like image 907
asikhalaban Avatar asked Feb 01 '26 06:02

asikhalaban


1 Answers

Depending on your distribution, the web server user (apache, www-data,?) is probably locked down and unable to write to it's $HOME. On Redhat/CentOS, the apache user $HOME is /usr/share/httpd/. When Matlab is started as that user, something in the string of processes will try to create a $HOME/.config or other user specific files and Matlab dies with the informative "transport stopped." Try this:

chown apache:apache /usr/share/httpd/

or the equivalent on your system. The user $HOME directory can be found with "getent passwd $USER", $HOME is the 6th : separated field.

If it's not this, then look for anything else Matlab expects to be able to do at startup which permissions will prevent as the webserver user.

Disclaimer: I have no idea what the security implications are of making this change.

like image 168
John Hanks Avatar answered Feb 02 '26 20:02

John Hanks