{"record":{"id":"f78b69cba01621cd","repo":"apache/beam","slug":"pid-file-must-be-specified-with-start","errorCode":null,"errorMessage":"--pid_file must be specified with --start","messagePattern":"--pid_file must be specified with --start","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/portability/local_job_service_main.py","lineNumber":97,"sourceCode":"    if not options.pid_file:\n      raise RuntimeError('--pid_file must be specified with --stop')\n    if os.path.exists(options.pid_file):\n      with open(options.pid_file) as fin:\n        pid = int(fin.read())\n      print('Killing process at', pid)\n      try:\n        os.kill(pid, signal.SIGTERM)\n      except Exception:\n        print('Process', pid, 'already killed.')\n      os.unlink(options.pid_file)\n    else:\n      print('Process id file', options.pid_file, 'already removed.')\n    if not options.background:\n      return\n\n  if options.background:\n    if not options.pid_file:\n      raise RuntimeError('--pid_file must be specified with --start')\n    if options.stop:\n      argv.remove('--stop')\n    argv.remove('--background')\n    if not options.port_file:\n      options.port_file = os.path.splitext(options.pid_file)[0] + '.port'\n      argv.append('--port_file')\n      argv.append(options.port_file)\n\n    if not options.stdout_file:\n      raise RuntimeError('--stdout_file must be specified with --background')\n    os.makedirs(pathlib.PurePath(options.stdout_file).parent, exist_ok=True)\n    stdout_dest = open(options.stdout_file, mode='w')\n\n    if options.stderr_file:\n      os.makedirs(pathlib.PurePath(options.stderr_file).parent, exist_ok=True)\n      stderr_dest = open(options.stderr_file, mode='w')\n    else:\n      stderr_dest = subprocess.STDOUT","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/portability/local_job_service_main.py#L79-L115","documentation":"The local_job_service_main.run() CLI entrypoint raises this RuntimeError when --background/--start daemonization is requested but no --pid_file was given. The pid file is required so the daemonized process can later be located and stopped via --stop.","triggerScenarios":"Running `python -m apache_beam.runners.portability.local_job_service_main --start` (or with --background) without passing --pid_file; options.pid_file is None when options.background is checked.","commonSituations":"Hand-writing a start command for a local Beam job server and forgetting the pid file; copying a stop command but omitting the flag pair used at start; scripts that set --stop without having recorded a pid file path.","solutions":["Add --pid_file /path/to/service.pid alongside --start/--background.","If you do not need daemonization, drop --start/--background and run in the foreground.","Reuse the same pid file path consistently between --start and --stop invocations."],"exampleFix":"// before\npython -m apache_beam.runners.portability.local_job_service_main --start --port 8099\n// after\npython -m apache_beam.runners.portability.local_job_service_main --start --port 8099 --pid_file /tmp/beam_job_service.pid","handlingStrategy":"validation","validationCode":"args = ['--start', '--port', '8099']\nassert '--pid_file' in args or '--pid_file=...' in args, 'pass --pid_file with --start'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair --start/--background with an explicit --pid_file path.","Reuse the same pid_file path for the later --stop invocation.","Wrap job-service launch scripts to validate required flags before exec."],"tags":["cli","missing-flag","daemonization"],"backgroundTag":"missing-required-flag","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}