Skip to content

Instantly share code, notes, and snippets.

@ryanmcgrath
Created April 9, 2016 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmcgrath/f759d0bbc3d670214884cb14c38e11b4 to your computer and use it in GitHub Desktop.
Save ryanmcgrath/f759d0bbc3d670214884cb14c38e11b4 to your computer and use it in GitHub Desktop.
Getting around uwsgidecorators import failure issues when using uwsgi spooler functionality.
try:
# This module is only available when running under uwsgi
# in production. We try to import it, but if it fails we're
# running in development and should just pass a decorator that'll
# run it back immediately.
from uwsgidecorators import spool
except:
def spool(fn):
def _spool(**kwargs):
return fn(kwargs)
fn.spool = _spool
return fn
@ryanmcgrath
Copy link
Author

If you use uwsgi, you can make use of the spooler functionality to avoid having to do the usual Celery+[workers/etc] setup. There's one annoying piece that's not well documented around the internet, which is that if you're using the @spool decorator/methods, and you're not running in uwsgi (like a development server) you'll have everything blow up as uwsgi injects the package for you under ordinary circumstances. This patches it so that, if you're not under uwsgi, it'll just auto-execute the spooler method. Works perfectly for me in development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment