[openstack-dev] Dealing with Popen and Eventlet
Adam Young
ayoung at redhat.com
Sat Nov 3 01:40:48 UTC 2012
Since Eventlet is based on continuations instead of threads or
processes, any call that blocks is going to lock up the webserver. That
is any I/O at all. Thus, when trying to figure out how best to call the
OpenSSL functions from Eventlet, I settled on what I thought would be
the best tested approach: spin it off as a separate process. And it
seemed to work.
Well, it doesn't work. The Eventlet library does not properly Monkey
patch the subprocess calls from Python. While this is something we
should patch upstream in Eventlet, we need something to deal with the
existing Eventlet library for Grizzly development.
I've been trying to make it possible to run Keystone (and the other
services eventually) in Apache. Thus, the simple solution of replacing
import subprocess
with
import eventlet.green.subprocess
Won't work. It solves the problem in Eventlet, but not apache.
It is possible to do something like this code below:
in the file keystone/common/interop/__init__.py
import sys
if 'eventlet' in sys.modules:
import eventlet.green.subprocess as interop_subprocess
print sys.modules["eventlet"]
else:
import subprocess as interop_subprocess
PIPE = interop_subprocess.PIPE
CalledProcessError = interop_subprocess.CalledProcessError
Popen = interop_subprocess.Popen
#end interop
and then, instead of
import eventlet.green.subprocess
we can import keystone.common.interop as subprocess
The problem is that the if statement is not triggered when this import
is hit, as the eventlet code has not yet been imported elsewhere.
What is the right way of detecting what web server we are running in and
selecting which version of the subprocess code to import?
More information about the OpenStack-dev
mailing list