MCPcopy Create free account
hub / github.com/openai/openai-agents-python / start_temporary_redis_server

Function start_temporary_redis_server

examples/run_examples.py:304–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

302
303
304def start_temporary_redis_server() -> TemporaryRedisServer | None:
305 redis_server = shutil.which("redis-server")
306 if redis_server is None:
307 return None
308
309 port = choose_loopback_port()
310 temp_dir = tempfile.TemporaryDirectory(prefix="examples-redis-")
311 url = f"redis://127.0.0.1:{port}/0"
312 process = subprocess.Popen(
313 [
314 redis_server,
315 "--bind",
316 "127.0.0.1",
317 "--port",
318 str(port),
319 "--save",
320 "",
321 "--appendonly",
322 "no",
323 "--dir",
324 temp_dir.name,
325 ],
326 stdout=subprocess.DEVNULL,
327 stderr=subprocess.DEVNULL,
328 )
329
330 server = TemporaryRedisServer(process=process, temp_dir=temp_dir, url=url)
331 deadline = time.monotonic() + 5
332 while time.monotonic() < deadline:
333 if process.poll() is not None:
334 server.close()
335 return None
336 if redis_ping_url(url, timeout=0.2):
337 return server
338 time.sleep(0.1)
339
340 server.close()
341 return None
342
343
344def prepare_redis_for_example(

Callers 1

Calls 4

closeMethod · 0.95
choose_loopback_portFunction · 0.85
redis_ping_urlFunction · 0.85

Tested by

no test coverage detected