Fix media repo breaking (#5593)

This commit is contained in:
Amber Brown 2019-07-03 04:01:28 +10:00 committed by Richard van der Hoff
parent f8b52eb8c5
commit 0ee9076ffe
6 changed files with 60 additions and 26 deletions

View file

@ -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