{"record":{"id":"ab39cd2618ebb013","repo":"apache/beam","slug":"pid-file-must-be-specified-with-stop","errorCode":null,"errorMessage":"--pid_file must be specified with --stop","messagePattern":"--pid_file must be specified with --stop","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/portability/local_job_service_main.py","lineNumber":80,"sourceCode":"      '--background',\n      action='store_true',\n      help='Start the server up as a background process.'\n      ' Will fail if pid_file already exists, unless --stop is also specified.')\n  parser.add_argument(\n      '--stderr_file',\n      help='Where to write stderr (if not specified, merged with stdout).')\n  parser.add_argument(\n      '--stdout_file', help='Where to write stdout for background job service.')\n  parser.add_argument(\n      '--stop',\n      action='store_true',\n      help='Stop the existing process, if any, specified in pid_file.'\n      ' Will not start up a new service unless --background is specified.')\n  options = parser.parse_args(argv)\n\n  if options.stop:\n    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:","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/portability/local_job_service_main.py#L62-L98","documentation":"local_job_service_main's run() validates CLI options: --stop requires --pid_file to know which process to kill. Passing --stop without --pid_file is a command-line usage error, so it raises RuntimeError immediately after parsing.","triggerScenarios":"Invoking `python -m apache_beam.runners.portability.local_job_service_main --stop` without also supplying --pid_file pointing at the file holding the service's PID.","commonSituations":"Copy-pasting only part of a documented stop command; forgetting that the pid_file was written to a custom path when the service was started; scripts calling --stop without persisting the pid file first.","solutions":["Add --pid_file=/path/to/pid pointing at the file created when the service started.","Restart the stop command exactly as used previously, including the same --pid_file path.","If the pid file is lost, find the process manually (pgrep -f local_job_service) and kill it directly."],"exampleFix":"// before\npython -m apache_beam.runners.portability.local_job_service_main --stop\n// after\npython -m apache_beam.runners.portability.local_job_service_main --stop --pid_file=/tmp/beam_service.pid","handlingStrategy":"validation","validationCode":"if args.stop and not args.pid_file:\n    parser.error('--pid_file must be specified with --stop')","typeGuard":null,"tryCatchPattern":"try:\n    main(argv)\nexcept RuntimeError as e:\n    if 'pid_file' in str(e): print_usage_and_exit(2)","preventionTips":["Always start the service with --pid_file so --stop works later","Script start/stop pairs together","Validate flags before submitting long commands"],"tags":["cli","argument-validation","process-management","beam"],"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"}