[openstack-dev] Dealing with Popen and Eventlet

Sandy Walsh sandy.walsh at RACKSPACE.COM
Sat Nov 3 01:57:03 UTC 2012


Interesting question, and sorry for my nativity, but do we use eventlet in a web server? I thought we leaned on the web server to deal with the threading and only used eventlet in the services?

Or am I missing something?

-S
  
________________________________________
From: Adam Young [ayoung at redhat.com]
Sent: Friday, November 02, 2012 10:40 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



More information about the OpenStack-dev mailing list