Answer the question
In order to leave comments, you need to log in
How to access a global variable from a service in python?
Friends, hello everyone!
I am writing my first web service in python, using the spyne -> mod_wsgi -> apache bundle, I raised the part that is responsible for communicating with the application. The application itself had to be taken out of mod_wsgi, because. each request reloads everything again and wildly slows down responses. How to move the application into RAM so that it can be launched once and only accessed through mod_wsgi?
Now I start the script in interactive mode:
def startup():
global model
from sklearn.externals import joblib
model= joblib.load('model')
print('Model_loaded')
global model
Answer the question
In order to leave comments, you need to log in
The problem is treated by mod_wsgi internal daemonization, here is an example of a working Apache config:
<VirtualHost *:80>
ServerName get
WSGIDaemonProcess pybsk processes=1 threads=5
WSGIScriptAlias /Get /var/www/python/pymain.py
WSGICallableObject 'application'
LogLevel info
DocumentRoot /var/www/python
<Directory /var/www/python>
WSGIProcessGroup get
WSGIApplicationGroup %{GLOBAL}
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
<IfDefine MOD_WSGI_LOAD_PYTHON_DYLIB>
LoadFile ''
</IfDefine>
WSGIMapHEADToGET Auto
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question