restructured code to get it work in wsgi mode. For example with uwsgi enamle master process '-m' option, but do not enable multiple processes(-p)