Permalink
Browse files

Include our own version of isgenerator() for Python 2.5 and below.

  • Loading branch information...
1 parent b800cee commit d1ac84d6ba67665a02d06efef1505a34d203a5ff Eric Naeseth committed Feb 25, 2010
Showing with 9 additions and 2 deletions.
  1. +9 −2 swirl.py
View
11 swirl.py
@@ -4,12 +4,19 @@
Provides some sugar to make Tornado's async stuff more palatable.
"""
-import inspect
import logging
import functools
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, asynchronous as web_async
+try:
+ from inspect import isgenerator
+except ImportError:
+ # Python < 2.6
+ import types
+ def isgenerator(obj):
+ return isinstance(obj, types.GeneratorType)
+
__version__ = '0.1.0'
def make_asynchronous_decorator(io_loop):
@@ -37,7 +44,7 @@ def run_async_routine(*args, **kwargs):
web_handler = None
gen = routine(*args, **kwargs)
- if not inspect.isgenerator(gen):
+ if not isgenerator(gen):
# the "coroutine" isn't actually a coroutine; just return
# its result like tornado.web.asynchronous would do
return gen

0 comments on commit d1ac84d

Please sign in to comment.