Create and start the target process for benchmarking
(temp_file, code_example="basic")
| 369 | |
| 370 | |
| 371 | def 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 | |
| 395 | def cleanup_process(process, temp_file_path): |