From 81110ccbd40465acee0431a1ac711eccd05b1b29 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 16 Oct 2015 10:12:11 -0700 Subject: [PATCH] automatically pick the best async_mode --- example/app.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/example/app.py b/example/app.py index 78881a03..2c499700 100755 --- a/example/app.py +++ b/example/app.py @@ -1,9 +1,31 @@ #!/usr/bin/env python -# set this variable to "threading", "eventlet" or "gevent" to test the -# different async modes -async_mode = 'threading' - +# Set this variable to "threading", "eventlet" or "gevent" to test the +# different async modes, or leave it set to None for the application to choose +# the best option based on available packages. +async_mode = 'gevent' + +if async_mode is None: + try: + import eventlet + async_mode = 'eventlet' + except ImportError: + pass + + if async_mode is None: + try: + from gevent import monkey + async_mode = 'gevent' + except ImportError: + pass + + if async_mode is None: + async_mode = 'threading' + + print('async_mode is ' + async_mode) + +# monkey patching is necessary because this application uses a background +# thread if async_mode == 'eventlet': import eventlet eventlet.monkey_patch()