def toplevel(func):
 synctaskletfunc = synctasklet(func)
 @utils.wrapping(func)
 def add_context_wrapper(*args, **kwds):
  __ndb_debug__ = utils.func_info(func)
  _state.clear_all_pending()
  ctx = make_default_context()
  try:
   set_context(ctx)
   return synctaskletfunc(*args, **kwds)
  finally:
   set_context(None)
   ctx.flush().check_success()
   eventloop.run()
 return add_context_wrapper

def toplevel ( func ) : synctaskletfunc = synctasklet ( func ) @ utils . wrapping ( func ) def add_context_wrapper ( * args , ** kwds ) : __ndb_debug__ = utils . func_info ( func ) _state . clear_all_pending ( ) ctx = make_default_context ( ) try : set_context ( ctx ) return synctaskletfunc ( * args , ** kwds ) finally : set_context ( None ) ctx . flush ( ) . check_success ( ) eventloop . run ( ) return add_context_wrapper
a sync tasklet that sets a fresh default context .