[openstack-dev] Dealing with Popen and Eventlet

Adam Young ayoung at redhat.com
Mon Nov 5 01:04:30 UTC 2012


On 11/02/2012 10:03 PM, Bhandaru, Malini K wrote:
> Hello Adam!
>
> A typical pattern is to have some singleton class, in this case something based on eventlet or its equivalent.
> If the eventlet module has been loaded, then this singleton class would already exist, else get created.
> Then you could essentially do your if.
> Or a factory class -- that would return the eventlet version or apache version based on the factory you have configured (via some config file)
> The factory class always returns your "interop_subprocess"
Yeah, I think I am going to have to make some sort of Popen bridge 
class, and load an instance of the  appropriate subclass  based on 
whether Eventlet is loaded or not.  Yuck.


>
> Regards
> Malini
>
>
> -----Original Message-----
> From: Adam Young [mailto:ayoung at redhat.com]
> Sent: Friday, November 02, 2012 6:41 PM
> To: OpenStack Development Mailing List
> Subject: [openstack-dev] Dealing with Popen and Eventlet
>
> 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?
>
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




More information about the OpenStack-dev mailing list