def runnable(fn, *args, **kwargs): """ Decorator to make a method into an asynchronous method run on a thread. Only supports threads do to a pickling problem with decorators across process boundaries. In addition, it sets up a cloned RequestContext so that data can be shared across RequestContext boundaries. The thread run within its own RequestContext boundary but has access to the data of the calling request. @runnable def foo(): pass :return: a Future """ # create a cloned copy of the existing RequestContext request_ctx = RequestContextManager.get_context().clone( ) if RequestContextManager.active() else None def execution_wrapper(): # enable RequestContext on current thread with StackContext(RequestContextManager(request_ctx).context_manager): return fn(*args, **kwargs) return Executor().get_executor(threaded=True).submit(execution_wrapper)
def active(self): return RequestContextManager.active() and \ "security_context" in RequestContextManager.get_context()
def _assert_request_context(self): if not RequestContextManager.active(): raise RequestContextError("Authentication provider cannot access request context.")
def request_context_scoped(self): return RequestContextManager.active()
def request_context_scoped(self): return RequestContextManager.active()
def get_requests(self): access_store = self.__request_store if RequestContextManager.active( ) else _local_access_history return access_store.history
def active(self): return RequestContextManager.active() and \ "security_context" in RequestContextManager.get_context()
def _assert_request_context(self): if not RequestContextManager.active(): raise RequestContextError( "Authentication provider cannot access request context.")