Beispiel #1
0
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)
Beispiel #2
0
 def active(self):
     return RequestContextManager.active() and \
         "security_context" in RequestContextManager.get_context()
Beispiel #3
0
 def _assert_request_context(self):
     if not RequestContextManager.active():
         raise RequestContextError("Authentication provider cannot access request context.")
Beispiel #4
0
 def request_context_scoped(self):
     return RequestContextManager.active()
Beispiel #5
0
 def request_context_scoped(self):
     return RequestContextManager.active()
Beispiel #6
0
 def get_requests(self):
     access_store = self.__request_store if RequestContextManager.active(
     ) else _local_access_history
     return access_store.history
Beispiel #7
0
 def active(self):
     return RequestContextManager.active() and \
         "security_context" in RequestContextManager.get_context()
Beispiel #8
0
 def _assert_request_context(self):
     if not RequestContextManager.active():
         raise RequestContextError(
             "Authentication provider cannot access request context.")