def augment_twisted_deferToThreadPool():
"""Wrap every function deferred to a thread in `synchronous`."""
from twisted.internet import threads
from twisted.internet.threads import deferToThreadPool
from provisioningserver.utils.twisted import ISynchronous, synchronous
def new_deferToThreadPool(reactor, threadpool, f, *args, **kwargs):
"""Variant of Twisted's that wraps all functions in `synchronous`."""
func = f if ISynchronous.providedBy(f) else synchronous(f)
return deferToThreadPool(reactor, threadpool, func, *args, **kwargs)
if threads.deferToThreadPool.__module__ != __name__:
threads.deferToThreadPool = new_deferToThreadPool
评论列表
文章目录