This blog is running on Django/Byteflow, using Spawning as WSGI server. After reading Eric’s post about Spawning, I’ve decided to give it a try, and found it convenient to work with.
Install
First thing, you need to install development version of python (python-dev package). Setuptools and libssl-dev are also required (python-setuptools, libssl-dev packages).
Other requirements are:
- eventlet (requires python-dev)
- greenlet
- PasteDeploy
- pyOpenSSL
- simplejson
Running Django site
The simplest way is to run
spawn --factory=spawning.django_factory.config_factory settings
from the Django project directory.
With Spawning 8.3 this method didn’t always work, because there was a bug with connected with adding current directory path to the PYTHONPATH variable. Apparently, it was fixed in the latest Spawning version from PyPi.
So alternative method to run Django and Spawning would be using Python scripts:
spawn_byteflow.py
#!/usr/bin/python
from spawning.spawning_controller import run_controller
import os.path, os
import sys
#workaraund for Spawning issue with PYTHONPATH
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
sys.path.insert(0, PROJECT_ROOT)
os.environ['PYTHONPATH']=':'.join(sys.path)
factory_args = {
'host': '',
'port': 9090,
'num_processes': 1,
'processpool_workers': 0,
'threadpool_workers': 10,
'watch': [],
'dev': True,
'deadman_timeout': 120,
'args': ['byteflow_wsgi.application'],
}
run_controller('spawning.wsgi_factory.config_factory', factory_args, None)
byteflow_wsgi.py
import os, sys
#Calculate the path based on the location of the WSGI script.
workspace = os.path.dirname(__file__)
sys.path.append(workspace)
sys.path.append(os.path.dirname(workspace))
#Add the path to 3rd party django application and to django itself.
os.environ['DJANGO_SETTINGS_MODULE'] = 'byteflow.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
The first script corrects Spawning 8.3 issue with a path, and runs the web server. The second script is a standard way to run Django using WSGI.







Comments
No comments for this post