diff options
author | Amber H. Brown <hawkowl@atleastfornow.net> | 2019-07-03 22:39:30 +1000 |
---|---|---|
committer | Amber H. Brown <hawkowl@atleastfornow.net> | 2019-07-03 22:39:30 +1000 |
commit | f4343c7d2bbde2d4b9674a029867bbe0353616e4 (patch) | |
tree | 44b29f777ae1418b1c858e2aa7cbbece06bafc70 /synapse/util/logcontext.py | |
parent | Merge remote-tracking branch 'origin/develop' into shhs (diff) | |
parent | 1.1.0rc2 (diff) | |
download | synapse-f4343c7d2bbde2d4b9674a029867bbe0353616e4.tar.xz |
Merge remote-tracking branch 'origin/develop' into shhs
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r-- | synapse/util/logcontext.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py index 6b0d2deea0..9e1b537804 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py @@ -24,6 +24,7 @@ See doc/log_contexts.rst for details on how this works. import logging import threading +import types from twisted.internet import defer, threads @@ -528,8 +529,9 @@ def run_in_background(f, *args, **kwargs): return from the function, and that the sentinel context is set once the deferred returned by the function completes. - Useful for wrapping functions that return a deferred which you don't yield - on (for instance because you want to pass it to deferred.gatherResults()). + Useful for wrapping functions that return a deferred or coroutine, which you don't + yield or await on (for instance because you want to pass it to + deferred.gatherResults()). Note that if you completely discard the result, you should make sure that `f` doesn't raise any deferred exceptions, otherwise a scary-looking @@ -544,6 +546,9 @@ def run_in_background(f, *args, **kwargs): # by synchronous exceptions, so let's turn them into Failures. return defer.fail() + if isinstance(res, types.CoroutineType): + res = defer.ensureDeferred(res) + if not isinstance(res, defer.Deferred): return res |