{"record":{"id":"fd4360d4c8246596","repo":"jax-ml/jax","slug":"only-one-profiler-server-can-be-active-at-a-time","errorCode":null,"errorMessage":"Only one profiler server can be active at a time.","messagePattern":"Only one profiler server can be active at a time\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/profiler.py","lineNumber":70,"sourceCode":"\ndef start_server(\n    port: int, requires_backend: bool = True\n) -> _profiler.ProfilerServer:\n  \"\"\"Starts the profiler server on port `port`.\n\n  Using the \"TensorFlow profiler\" feature in `TensorBoard\n  <https://www.tensorflow.org/tensorboard>`_ 2.2 or newer, you can\n  connect to the profiler server and sample execution traces that show CPU,\n  GPU, and/or TPU device activity.\n\n  Args:\n    port: The port to start the profiler server on.\n    requires_backend: If False, the profiler server will not wait for backends\n      to be initialized before starting. Default is True.\n  \"\"\"\n  global _profiler_server\n  if _profiler_server is not None:\n    raise ValueError(\"Only one profiler server can be active at a time.\")\n\n  # Make sure backends are initialized before creating a profiler\n  # session. Otherwise on Cloud TPU, libtpu may not be initialized before\n  # creating the tracer, which will cause the TPU tracer initialization to\n  # fail and no TPU operations will be included in the profile.\n  # NOTE(skyewm): I'm not sure this is necessary for start_server (is definitely\n  # is for start_trace), but I'm putting it here to be safe.\n  if requires_backend:\n    xla_bridge.get_backend()\n\n  _profiler_server = _profiler.start_server(port)\n  return _profiler_server\n\n\ndef stop_server():\n  \"\"\"Stops the running profiler server.\"\"\"\n  global _profiler_server\n  if _profiler_server is None:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/profiler.py#L52-L88","documentation":"jax.profiler.start_server is a process-global singleton; a second call while a server is already running raises ValueError. The module-level `_profiler_server` guard enforces one profiler server per process.","triggerScenarios":"Calling `jax.profiler.start_server(port)` twice, e.g. in repeated notebook cell runs, test setup that runs per-test, or both library and user code starting a server.","commonSituations":"Test suites calling start_server in setUp without stop_server in tearDown; long-running servers where an init path may run twice; Kaggle/colab cell re-execution.","solutions":["Call `jax.profiler.stop_server()` before starting again","Guard with a module-level flag or try/except around start_server","In tests, use setUp/tearDown pairing so each start is matched by a stop"],"exampleFix":"# before\njax.profiler.start_server(9999)  # second call fails\n# after\ntry:\n  jax.profiler.start_server(9999)\nexcept ValueError:\n  jax.profiler.stop_server()\n  jax.profiler.start_server(9999)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    jax.profiler.start_server(port)\nexcept ValueError as e:\n    if 'Only one profiler server' in str(e):\n        jax.profiler.stop_server()\n        jax.profiler.start_server(port)\n    else:\n        raise","preventionTips":["Maintain a started flag; stop before restart","Pair start/stop in setUp/tearDown in tests"],"tags":["jax","profiler","singleton"],"backgroundTag":"singleton-already-initialized","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}