Skip to content

Instantly share code, notes, and snippets.

@j00bar
Created December 18, 2012 23:51
Show Gist options
  • Save j00bar/4333196 to your computer and use it in GitHub Desktop.
Save j00bar/4333196 to your computer and use it in GitHub Desktop.
class WSGIApp(object):
POST_PROCESSING_TIMEOUT = 3
def async_response_handler(self, request, response):
log.debug('Running async handler')
time.sleep(2)
log.debug('Finished async handler')
def __call__(self, environ, start_response):
# snip
log.debug('Dispatching post-response handlers...')
gevent.spawn(
lambda *args, **kwargs: gevent.with_timeout(self.POST_PROCESSING_TIMEOUT,
self.async_response_handler, *args, **kwargs),
request, response)
log.debug('Rendering response...')
return response(environ, start_response)
# log output reads....
DEBUG:base:Dispatching post-response handlers...
DEBUG:base:Running async handler
DEBUG:base:Finished async handler
DEBUG:base:Rendering response...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment