MCPcopy
hub / github.com/redis/redis-py / run_recurring_coro

Method run_recurring_coro

redis/background.py:88–110  ·  view source on GitHub ↗

Runs recurring coroutine with given interval in seconds in a background thread. Uses a shared event loop to ensure connection pools remain valid across calls. This is useful for sync code that needs to run async health checks.

(
        self, interval: float, coro: Callable[..., Coroutine[Any, Any, Any]], *args
    )

Source from the content-addressed store, hash-verified

86 thread.start()
87
88 def run_recurring_coro(
89 self, interval: float, coro: Callable[..., Coroutine[Any, Any, Any]], *args
90 ):
91 """
92 Runs recurring coroutine with given interval in seconds in a background thread.
93 Uses a shared event loop to ensure connection pools remain valid across calls.
94
95 This is useful for sync code that needs to run async health checks.
96 """
97 with self._lock:
98 if self._stopped:
99 return
100
101 # Use the shared health check loop, creating it if needed
102 self._ensure_health_check_loop()
103
104 with self._lock:
105 loop = self._health_check_loop
106
107 # Schedule recurring execution in the shared loop
108 loop.call_soon_threadsafe(
109 self._call_later_recurring_coro, loop, interval, coro, *args
110 )
111
112 def run_coro_sync(
113 self,

Calls 1