[Core] Fix Twisted fromCoroutine AttrError
Users with older versions of Twisted <= 21.2 were encoutering the following error: File "/home/calum/projects/deluge/deluge/decorators.py", line 191, in activate d = defer.Deferred.fromCoroutine(self.coro) builtins.AttributeError: type object 'Deferred' has no attribute 'fromCoroutine' Fixed by falling back to ensureDeferred since fromCoroutine was introduced in Twisted 21.2 as a saner name for handling of coroutines. Ref: https://twistedmatrix.com/trac/ticket/9825
This commit is contained in:
parent
03938839e0
commit
055a84bb15
|
@ -188,7 +188,11 @@ class CoroutineDeferred(defer.Deferred):
|
|||
"""If the result wasn't awaited before the next context switch, we turn it into a deferred."""
|
||||
if self.awaited is None:
|
||||
self.awaited = False
|
||||
d = defer.Deferred.fromCoroutine(self.coro)
|
||||
try:
|
||||
d = defer.Deferred.fromCoroutine(self.coro)
|
||||
except AttributeError:
|
||||
# Fallback for Twisted <= 21.2 without fromCoroutine
|
||||
d = defer.ensureDeferred(self.coro)
|
||||
d.chainDeferred(self)
|
||||
|
||||
def addCallbacks(self, *args, **kwargs): # noqa: N802
|
||||
|
@ -208,8 +212,7 @@ def maybe_coroutine(
|
|||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
# Uncomment for quick testing to make sure CoroutineDeferred magic isn't at fault
|
||||
# from twisted.internet.defer import ensureDeferred
|
||||
# return ensureDeferred(f(*args, **kwargs))
|
||||
# return defer.ensureDeferred(f(*args, **kwargs))
|
||||
return CoroutineDeferred(f(*args, **kwargs))
|
||||
|
||||
return wrapper
|
||||
|
|
Loading…
Reference in New Issue