Example #1
0
    def call_later(self, delay, callback, *args, **kwargs) -> IDelayedCall:
        """Call something later

        Note that the function will be called with no logcontext, so if it is anything
        other than trivial, you probably want to wrap it in run_as_background_process.

        Args:
            delay(float): How long to wait in seconds.
            callback(function): Function to call
            *args: Postional arguments to pass to function.
            **kwargs: Key arguments to pass to function.
        """
        def wrapped_callback(*args, **kwargs):
            with context.PreserveLoggingContext():
                callback(*args, **kwargs)

        with context.PreserveLoggingContext():
            return self._reactor.callLater(delay, wrapped_callback, *args,
                                           **kwargs)
Example #2
0
 def sleep(self, seconds: float) -> "Generator[Deferred[float], Any, Any]":
     d: defer.Deferred[float] = defer.Deferred()
     with context.PreserveLoggingContext():
         self._reactor.callLater(seconds, d.callback, seconds)
         res = yield d
     return res
Example #3
0
 def wrapped_callback(*args, **kwargs):
     with context.PreserveLoggingContext():
         callback(*args, **kwargs)
Example #4
0
 def sleep(self, seconds):
     d = defer.Deferred()
     with context.PreserveLoggingContext():
         self._reactor.callLater(seconds, d.callback, seconds)
         res = yield d
     return res
Example #5
0
 def wrapped_callback(*args: Any, **kwargs: Any) -> None:
     with context.PreserveLoggingContext():
         callback(*args, **kwargs)