Skip to content

Commit

Permalink
automatically pick the best async_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 16, 2015
1 parent 37316d7 commit 81110cc
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions example/app.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 81110cc

Please sign in to comment.