def inthread(func):
 @wraps(func)
 def wrapped(*a, **kw):
  return threads.deferToThread(func, *a, **kw)
 return wrapped

def inthread ( func ) : @ wraps ( func ) def wrapped ( * a , ** kw ) : return threads . deferToThread ( func , * a , ** kw ) return wrapped
decorator to call a function in a thread and return a deferred with the result .