Skip to content

Instantly share code, notes, and snippets.

@richvdh
Created March 7, 2017 23:41
Show Gist options
  • Save richvdh/39e794f43e3641deb7889e16cb2143d9 to your computer and use it in GitHub Desktop.
Save richvdh/39e794f43e3641deb7889e16cb2143d9 to your computer and use it in GitHub Desktop.
deferred test
@defer.inlineCallbacks
def test():
with LoggingContext("TEST") as x:
x.request = "TEST"
yield test_handler()
@defer.inlineCallbacks
def test_handler():
deferreds = [do_stuff(x) for x in ["bob", "chris"]]
yield preserve_context_over_deferred(defer.gatherResults(deferreds))
@defer.inlineCallbacks
def do_stuff(arg):
yield hs.get_datastore().get_user_by_id(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment