Use importutils.try_import for optional eventlet imports

Instead of doing try: except ImportError for eventlet imports
use the oslo.utils importutils.try_import function that safely
does the same with less verbosity for the optional usage of
eventlet imports/code that we have.

Change-Id: I7eaa7c5908ffb04282892c9f6af04044b73f4f8c
This commit is contained in:
Joshua Harlow
2015-01-25 11:08:57 -08:00
parent 1ae7a8e67b
commit 97797abb51
3 changed files with 12 additions and 16 deletions

View File

@@ -20,15 +20,13 @@ import threading
from concurrent import futures as _futures from concurrent import futures as _futures
from concurrent.futures import process as _process from concurrent.futures import process as _process
from concurrent.futures import thread as _thread from concurrent.futures import thread as _thread
from oslo_utils import importutils
from oslo_utils import reflection from oslo_utils import reflection
try: greenpatcher = importutils.try_import('eventlet.patcher')
from eventlet.green import threading as greenthreading greenpool = importutils.try_import('eventlet.greenpool')
from eventlet import greenpool greenqueue = importutils.try_import('eventlet.queue')
from eventlet import patcher as greenpatcher greenthreading = importutils.try_import('eventlet.green.threading')
from eventlet import queue as greenqueue
except ImportError:
pass
from taskflow.types import timing from taskflow.types import timing
from taskflow.utils import eventlet_utils as eu from taskflow.utils import eventlet_utils as eu

View File

@@ -16,11 +16,9 @@
from concurrent import futures as _futures from concurrent import futures as _futures
from concurrent.futures import _base from concurrent.futures import _base
from oslo_utils import importutils
try: greenthreading = importutils.try_import('eventlet.green.threading')
from eventlet.green import threading as greenthreading
except ImportError:
pass
from taskflow.types import futures from taskflow.types import futures
from taskflow.utils import eventlet_utils as eu from taskflow.utils import eventlet_utils as eu

View File

@@ -14,11 +14,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
try: from oslo_utils import importutils
import eventlet as _eventlet # noqa
EVENTLET_AVAILABLE = True _eventlet = importutils.try_import('eventlet')
except ImportError:
EVENTLET_AVAILABLE = False EVENTLET_AVAILABLE = bool(_eventlet)
def check_for_eventlet(exc=None): def check_for_eventlet(exc=None):