MCPcopy Index your code
hub / github.com/python/cpython / create_target_process

Function create_target_process

Tools/inspection/benchmark_external_inspection.py:371–392  ·  view source on GitHub ↗

Create and start the target process for benchmarking

(temp_file, code_example="basic")

Source from the content-addressed store, hash-verified

369
370
371def create_target_process(temp_file, code_example="basic"):
372 """Create and start the target process for benchmarking"""
373 example_info = CODE_EXAMPLES.get(code_example, {"code": CODE})
374 selected_code = example_info["code"]
375 temp_file.write(selected_code)
376 temp_file.flush()
377
378 process = subprocess.Popen(
379 [sys.executable, temp_file.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE
380 )
381
382 # Give it time to start
383 time.sleep(1.0)
384
385 # Check if it's still running
386 if process.poll() is not None:
387 stdout, stderr = process.communicate()
388 raise RuntimeError(
389 f"Target process exited unexpectedly:\nSTDOUT: {stdout.decode()}\nSTDERR: {stderr.decode()}"
390 )
391
392 return process, temp_file.name
393
394
395def cleanup_process(process, temp_file_path):

Callers 1

mainFunction · 0.85

Calls 7

pollMethod · 0.95
communicateMethod · 0.95
getMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45
sleepMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…