diff options
author | Amber Brown <hawkowl@atleastfornow.net> | 2019-07-03 04:01:28 +1000 |
---|---|---|
committer | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2019-07-02 19:01:28 +0100 |
commit | 0ee9076ffe40140db5e86763af077efbdb5d86b0 (patch) | |
tree | acab7d2c00d9daeaf45e7c5eeee9e6cf1f8f60af /synapse/util | |
parent | tweak changelog (diff) | |
download | synapse-0ee9076ffe40140db5e86763af077efbdb5d86b0.tar.xz |
Fix media repo breaking (#5593)
Diffstat (limited to 'synapse/util')
-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 |