{"record":{"id":"453ace15cece8327","repo":"python/cpython","slug":"d3-flame-graph-library-failed-to-load","errorCode":null,"errorMessage":"d3-flame-graph library failed to load","messagePattern":"d3-flame-graph library failed to load","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Lib/profiling/sampling/_flamegraph_assets/flamegraph.js","lineNumber":537,"sourceCode":"    if (this._tooltip) {\n      this._tooltip.transition().duration(150).style(\"opacity\", 0);\n    }\n    clearStatusBar();\n  };\n\n  return pythonTooltip;\n}\n\n// ============================================================================\n// Flamegraph Creation\n// ============================================================================\n\nfunction ensureLibraryLoaded() {\n  if (typeof flamegraph === \"undefined\") {\n    console.error(\"d3-flame-graph library not loaded\");\n    document.getElementById(\"chart\").innerHTML =\n      '<div style=\"padding: 40px; text-align: center; color: var(--text-muted);\">Error: d3-flame-graph library failed to load</div>';\n    throw new Error(\"d3-flame-graph library failed to load\");\n  }\n}\n\nconst HEAT_THRESHOLDS = [\n  [0.6, 8],\n  [0.35, 7],\n  [0.18, 6],\n  [0.12, 5],\n  [0.06, 4],\n  [0.03, 3],\n  [0.01, 2],\n];\n\nfunction getHeatLevel(percentage) {\n  for (const [threshold, level] of HEAT_THRESHOLDS) {\n    if (percentage >= threshold) return level;\n  }\n  return 1;","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js#L519-L555","documentation":"Raised by _ProactorBaseWritePipeTransport.write() when a sendfile operation (loop.sendfile / _sendfile_native) is currently in progress on the transport. During sendfile the transport parks an '_empty_waiter' future and ordinary buffered writes are forbidden because they would interleave with the file transfer. It is a transient, state-based error caused by concurrent use of one transport from two tasks.","triggerScenarios":"Calling transport.write() (directly or via a writer) while loop.sendfile(transport, file, ...) is still running on the same transport on a Windows proactor event loop. Also triggered by any custom use of the internal _empty_waiter mechanism.","commonSituations":"A server task streams a file with sendfile while another task writes headers/keepalives on the same connection; benchmark or copy utilities that mix sendfile with manual writes; code that assumes sendfile returns after queuing rather than after completion (not awaiting it).","solutions":["Await the sendfile() coroutine fully before issuing any write() on the same transport","Restructure so a single task owns the transport: serialize writes and sendfile through one writer coroutine or an asyncio.Lock","If interleaving is intentional, use sock_sendfile via raw socket API or write the file in chunks with write() instead of sendfile()","Catch RuntimeError with a retry-after-awaiting-drain only if you can confirm sendfile has completed"],"exampleFix":"# before\nasyncio.create_task(loop.sendfile(tr, f))\ntr.write(b'next request')  # RuntimeError: sendfile in progress\n# after\nawait loop.sendfile(tr, f)\ntr.write(b'next request')","handlingStrategy":"validation","validationCode":"async def send_file_then_write(loop, tr, f, payload):\n    await loop.sendfile(tr, f)      # fully awaited: no in-progress window\n    tr.write(payload)","typeGuard":null,"tryCatchPattern":"try:\n    tr.write(data)\nexcept RuntimeError as e:\n    if 'sendfile is in progress' in str(e):\n        await asyncio.sleep(0)  # let sendfile progress; real fix is sequencing\n        raise","preventionTips":["Always await sendfile() to completion before any write","Own each transport from exactly one writer task or guard it with a lock","Chunk the file with write() if interleaved writes are required","Never fire-and-forget sendfile via create_task and continue writing"],"tags":["asyncio","sendfile","windows","concurrency","transport"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}