MCPcopy Create free account
hub / github.com/Bareflank/hypervisor / Process

Class Process

utils/iwyu_tool.py:232–271  ·  view source on GitHub ↗

Manages an IWYU process in flight

Source from the content-addressed store, hash-verified

230
231
232class Process(object):
233 """ Manages an IWYU process in flight """
234 def __init__(self, proc, outfile, source_file):
235 self.proc = proc
236 self.outfile = outfile
237 self.output = None
238 self.source_file = source_file
239
240 def poll(self):
241 """ Return the exit code if the process has completed, None otherwise.
242 """
243 return self.proc.poll()
244
245 @property
246 def returncode(self):
247 return self.proc.returncode
248
249 def get_output(self):
250 """ Return stdout+stderr output of the process.
251
252 This call blocks until the process is complete, then returns the output.
253 """
254 if not self.output:
255 self.proc.wait()
256 self.outfile.seek(0)
257 self.output = self.outfile.read().decode("utf-8")
258 self.outfile.close()
259
260 return self.output
261
262 @classmethod
263 def start(cls, invocation):
264 """ Start a Process for the invocation and capture stdout+stderr. """
265 outfile = tempfile.TemporaryFile(prefix='iwyu')
266 process = subprocess.Popen(
267 invocation.command,
268 cwd=invocation.cwd,
269 stdout=outfile,
270 stderr=subprocess.STDOUT)
271 return cls(process, outfile, invocation.source_file)
272
273
274class Invocation(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected