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()