I am trying to deploy a Flask api via Apache/mod_wsgi. The api uses Gevent to provide concurrency for a recursive method. However, it is throwing the following error
[Mon Feb 08 12:05:37 2016] [error] error: cannot switch to a different thread
[Mon Feb 08 12:05:37 2016] [error] <callback at 0x1094ee350 args=()> failed with error
The entire api runs just fine using Gevent when run using Pycharm's built-in web server, and the api runs fine deployed using Apache/mod_wsgi when I don't use gevent to provide concurrency.
I assume that this should be runnable in Apache, but I so far have not been able to find a solution. I keep seeing mention of monkey patching, so I added this line to the module in which gevent is called
from gevent import monkey; monkey.patch_all()
but, that did not seem to help.
I found this bit on standalone WSGI containers in the Flask documentation (http://flask.pocoo.org/docs/0.10/deploying/wsgi-standalone/):
Gevent is a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of libevent event loop:
from gevent.wsgi import WSGIServer
from yourapplication import app
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()
It also says that
There are popular servers written in Python that contain WSGI applications and serve HTTP. These servers stand alone when they run; you can proxy to them from your web server. Note the section on Proxy Setups if you run into issues.
Do I need to ditch use of mod_wsgi and use Gevent's built in WSGI server and then proxy it via Apache? This would be a royal PITA, especially to deal with CORS issues (we have a web UI that accesses the api on the same server, and proxying from a different port would cause cross origin issues galore - unless someone can convince me otherwise).
Any insight on what to try next would be most appreciated.