def nestAndPrint():
  """Adds a python function frame and then prints the stacktrace."""
  # Python's traceback is not so useful.
  # import traceback; traceback.print_stack()

  # Ours is a bit better.
  print stacktrace()

  print '\n\n\n'
def countdown(i):
  """Countdown function to generate chained asynchronous calls."""
  if not i:
    reactor.stop()
    return

  print 'i is %d with frame %s' % (i, AsyncFrame.currentFrame.getName())

  yield time.sleep(0.01)

  print 'done sleeping with frame %s' % AsyncFrame.currentFrame.getName()

  if i % 2:
    nestAndPrint()
    yield dispatchOdd(i - 1)
  else:
    print stacktrace()
    yield dispatchEven(i - 1)