MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / __enter__

Method __enter__

demo/imdb/disposableredis/__init__.py:37–65  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

35
36
37 def __enter__(self):
38 if self._port is None:
39 self.port = get_random_port()
40 else:
41 self.port = self._port
42 args = [self.path,
43 '--port', str(self.port),
44 '--dir', tempfile.gettempdir(),
45 '--save', ''] + self.extra_args
46
47 self.process = subprocess.Popen(
48 args,
49 #cwd=os.getcwd(),
50 stdin=subprocess.PIPE,
51 stdout=open(os.devnull, 'w')
52 )
53
54 while True:
55 try:
56 self.client().ping()
57
58 break
59 except redis.ConnectionError:
60 self.process.poll()
61 if self.process.returncode is not None:
62 raise RuntimeError("Process has exited")
63 time.sleep(0.1)
64
65 return self.client()
66
67 def __exit__(self, exc_type, exc_val, exc_tb):
68 self.process.terminate()

Callers

nothing calls this directly

Calls 3

clientMethod · 0.95
strFunction · 0.85
get_random_portFunction · 0.70

Tested by

no test coverage detected