Navigation Menu

Skip to content

Commit

Permalink
Fix a serious bug that would cause the first work item to be repeated…
Browse files Browse the repository at this point in the history
… on every yield.
  • Loading branch information
Eric Naeseth committed Jan 20, 2010
1 parent bfd62de commit 8551b88
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions swirl.py
Expand Up @@ -42,28 +42,28 @@ def run_async_routine(*args, **kwargs):
# its result like tornado.web.asynchronous would do
return gen

work = None
work = [None]
def execute_work():
return work(callback_proxy)
return work[0](callback_proxy)

def callback_proxy(*args):
is_err = lambda val: isinstance(val, Exception)
try:
if len(args) > 0:
if is_err(args[-1]):
work = gen.throw(args[-1])
work[0] = gen.throw(args[-1])
elif (hasattr(args[0], 'error') and
is_err(args[0].error)):
work = gen.throw(args[0].error)
work[0] = gen.throw(args[0].error)
else:
if args[-1] is None:
args = args[:-1]
if len(args) == 1:
work = gen.send(args[0])
work[0] = gen.send(args[0])
else:
work = gen.send(args)
work[0] = gen.send(args)
else:
work = gen.next()
work[0] = gen.next()
io_loop.add_callback(execute_work)
except StopIteration:
if web_handler:
Expand All @@ -77,7 +77,7 @@ def callback_proxy(*args):
web_handler._handle_request_exception(e)

try:
work = gen.next()
work[0] = gen.next()
except StopIteration:
return None

Expand Down

0 comments on commit 8551b88

Please sign in to comment.