[{"data":1,"prerenderedAt":3235},["ShallowReactive",2],{"page-\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fcancelling-async-tasks-on-ctrl-c\u002F":3,"content-directory":2688},{"id":4,"title":5,"body":6,"date":2674,"description":2675,"difficulty":2676,"draft":2677,"extension":2678,"meta":2679,"navigation":195,"path":2680,"seo":2681,"stem":2682,"tags":2683,"updated":2674,"__hash__":2687},"content\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fcancelling-async-tasks-on-ctrl-c\u002Findex.md","Cancelling Async Tasks on Ctrl+C in Python CLIs",{"type":7,"value":8,"toc":2654},"minimark",[9,36,41,70,74,103,107,134,143,147,154,962,1500,1505,1534,1548,1560,1570,1573,1577,1580,1671,1674,1678,1681,1743,1747,1760,2510,2522,2526,2544,2548,2552,2562,2569,2582,2590,2598,2602,2617,2621,2650],[10,11,12,13,17,18,21,22,25,26,29,30,35],"p",{},"An async command is mirroring 120 files with eight concurrent downloads. The user realises they pointed it at the wrong bucket and presses Ctrl+C. What should happen is obvious: stop starting new downloads, abandon the ones in progress, remove their partial files, say what was done, and exit — within a second. What often happens instead is a wall of ",[14,15,16],"code",{},"Task was destroyed but it is pending!"," warnings, a ",[14,19,20],{},"CancelledError"," traceback, half-written files left behind, or a tool that ignores the first Ctrl+C entirely because some ",[14,23,24],{},"except Exception"," swallowed the cancellation. This guide explains how cancellation actually flows through ",[14,27,28],{},"asyncio",", and how to write async CLI code that stops cleanly and reports honestly. It is part of the ",[31,32,34],"a",{"href":33},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002F","concurrency and async topic",".",[37,38,40],"h2",{"id":39},"prerequisites","Prerequisites",[42,43,44,56,63],"ul",{},[45,46,47,48,51,52,55],"li",{},"Python 3.11+ — the behaviour described relies on ",[14,49,50],{},"asyncio.run","'s signal handling and ",[14,53,54],{},"TaskGroup",", both improved in 3.11.",[45,57,58,59,35],{},"An async command, bridged into Typer or Click as in ",[31,60,62],{"href":61},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frunning-async-code-in-typer-and-click\u002F","running async code in Typer and Click",[45,64,65,66,35],{},"Familiarity with the synchronous story in ",[31,67,69],{"href":68},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly\u002F","handling KeyboardInterrupt cleanly",[37,71,73],{"id":72},"how-ctrlc-travels-through-asyncio","How Ctrl+C travels through asyncio",[10,75,76,77,80,81,84,85,88,89,91,92,96,97,99,100,102],{},"When the terminal sends ",[14,78,79],{},"SIGINT",", Python normally raises ",[14,82,83],{},"KeyboardInterrupt"," wherever the main thread happens to be — which, in an async program, is usually deep inside the event loop's machinery, where an exception can corrupt its state. Since Python 3.11, ",[14,86,87],{},"asyncio.run()"," installs its own ",[14,90,79],{}," handler instead. On the first Ctrl+C it ",[93,94,95],"strong",{},"cancels the main task","; the cancellation propagates down through everything that task is awaiting; once the main task has finished unwinding, ",[14,98,87],{}," raises ",[14,101,83],{}," to its caller.",[104,105],"inline-diagram",{"name":106},"cc-cancel-sequence",[10,108,109,110,112,113,116,117,120,121,124,125,127,128,130,131,133],{},"Cancellation arrives inside each task as a ",[14,111,20],{}," raised at the ",[14,114,115],{},"await"," where the task is suspended. That means cleanup code in ",[14,118,119],{},"finally"," blocks and ",[14,122,123],{},"async with"," exits runs normally, as long as nothing catches and discards the ",[14,126,20],{}," on its way up. If the user presses Ctrl+C a second time before shutdown finishes, ",[14,129,87],{}," stops waiting and raises ",[14,132,83],{}," immediately — the escape hatch for cleanup that hangs.",[10,135,136,139,140,142],{},[14,137,138],{},"asyncio.TaskGroup"," completes the picture: when the task running the group is cancelled, the group cancels every child task and waits for all of them to finish before letting the cancellation continue. No child can outlive the ",[14,141,123],{}," block, so there are no orphaned tasks and no \"destroyed but pending\" warnings.",[37,144,146],{"id":145},"the-recipe","The recipe",[10,148,149,150,153],{},"The example mirrors a list of URLs into a directory. Each download writes to a ",[14,151,152],{},".part"," file and renames it on success; cancellation removes the partial file. A small state object tracks what happened, so the command can report it even after an interrupt.",[155,156,161],"pre",{"className":157,"code":158,"language":159,"meta":160,"style":160},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fmirror.py\nfrom __future__ import annotations\n\nimport asyncio\nimport os\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\n\nimport httpx\n\n\n@dataclass\nclass MirrorState:\n    total: int\n    done: list[str] = field(default_factory=list)\n    cancelled: list[str] = field(default_factory=list)\n    failed: dict[str, str] = field(default_factory=dict)\n\n    @property\n    def not_started(self) -> int:\n        return self.total - len(self.done) - len(self.cancelled) - len(self.failed)\n\n\nasync def fetch_one(client: httpx.AsyncClient, url: str, dest: Path, state: MirrorState) -> None:\n    part = dest.with_name(dest.name + \".part\")\n    try:\n        async with client.stream(\"GET\", url) as response:\n            response.raise_for_status()\n            with part.open(\"wb\") as fh:\n                async for chunk in response.aiter_bytes(64 * 1024):\n                    fh.write(chunk)\n        # The rename is quick and must not be half-done: protect it from cancellation.\n        await asyncio.shield(asyncio.to_thread(os.replace, part, dest))\n        state.done.append(url)\n    except asyncio.CancelledError:\n        state.cancelled.append(url)\n        raise                                   # never swallow cancellation\n    except httpx.HTTPError as exc:\n        state.failed[url] = str(exc) or type(exc).__name__\n    finally:\n        part.unlink(missing_ok=True)            # gone on success (renamed) or failure\n\n\nasync def mirror(urls: list[str], out: Path, jobs: int, state: MirrorState) -> None:\n    sem = asyncio.Semaphore(jobs)\n    out.mkdir(parents=True, exist_ok=True)\n    async with httpx.AsyncClient(timeout=httpx.Timeout(30.0, connect=5.0),\n                                 follow_redirects=True) as client:\n\n        async def guarded(url: str) -> None:\n            async with sem:\n                name = httpx.URL(url).path.rsplit(\"\u002F\", 1)[-1] or \"index.html\"\n                await fetch_one(client, url, out \u002F name, state)\n\n        async with asyncio.TaskGroup() as tg:\n            for url in urls:\n                tg.create_task(guarded(url))\n","python","",[14,162,163,172,190,197,206,214,227,240,245,253,258,263,270,282,291,321,343,371,376,385,402,451,456,461,486,506,514,538,544,564,594,600,606,615,621,630,636,645,658,684,692,712,717,722,749,760,784,819,836,841,863,874,907,922,927,942,956],{"__ignoreMap":160},[164,165,168],"span",{"class":166,"line":167},"line",1,[164,169,171],{"class":170},"sJ8bj","# src\u002Fmytool\u002Fmirror.py\n",[164,173,175,179,183,186],{"class":166,"line":174},2,[164,176,178],{"class":177},"szBVR","from",[164,180,182],{"class":181},"sj4cs"," __future__",[164,184,185],{"class":177}," import",[164,187,189],{"class":188},"sVt8B"," annotations\n",[164,191,193],{"class":166,"line":192},3,[164,194,196],{"emptyLinePlaceholder":195},true,"\n",[164,198,200,203],{"class":166,"line":199},4,[164,201,202],{"class":177},"import",[164,204,205],{"class":188}," asyncio\n",[164,207,209,211],{"class":166,"line":208},5,[164,210,202],{"class":177},[164,212,213],{"class":188}," os\n",[164,215,217,219,222,224],{"class":166,"line":216},6,[164,218,178],{"class":177},[164,220,221],{"class":188}," dataclasses ",[164,223,202],{"class":177},[164,225,226],{"class":188}," dataclass, field\n",[164,228,230,232,235,237],{"class":166,"line":229},7,[164,231,178],{"class":177},[164,233,234],{"class":188}," pathlib ",[164,236,202],{"class":177},[164,238,239],{"class":188}," Path\n",[164,241,243],{"class":166,"line":242},8,[164,244,196],{"emptyLinePlaceholder":195},[164,246,248,250],{"class":166,"line":247},9,[164,249,202],{"class":177},[164,251,252],{"class":188}," httpx\n",[164,254,256],{"class":166,"line":255},10,[164,257,196],{"emptyLinePlaceholder":195},[164,259,261],{"class":166,"line":260},11,[164,262,196],{"emptyLinePlaceholder":195},[164,264,266],{"class":166,"line":265},12,[164,267,269],{"class":268},"sScJk","@dataclass\n",[164,271,273,276,279],{"class":166,"line":272},13,[164,274,275],{"class":177},"class",[164,277,278],{"class":268}," MirrorState",[164,280,281],{"class":188},":\n",[164,283,285,288],{"class":166,"line":284},14,[164,286,287],{"class":188},"    total: ",[164,289,290],{"class":181},"int\n",[164,292,294,297,300,303,306,309,313,315,318],{"class":166,"line":293},15,[164,295,296],{"class":188},"    done: list[",[164,298,299],{"class":181},"str",[164,301,302],{"class":188},"] ",[164,304,305],{"class":177},"=",[164,307,308],{"class":188}," field(",[164,310,312],{"class":311},"s4XuR","default_factory",[164,314,305],{"class":177},[164,316,317],{"class":181},"list",[164,319,320],{"class":188},")\n",[164,322,324,327,329,331,333,335,337,339,341],{"class":166,"line":323},16,[164,325,326],{"class":188},"    cancelled: list[",[164,328,299],{"class":181},[164,330,302],{"class":188},[164,332,305],{"class":177},[164,334,308],{"class":188},[164,336,312],{"class":311},[164,338,305],{"class":177},[164,340,317],{"class":181},[164,342,320],{"class":188},[164,344,346,349,351,354,356,358,360,362,364,366,369],{"class":166,"line":345},17,[164,347,348],{"class":188},"    failed: dict[",[164,350,299],{"class":181},[164,352,353],{"class":188},", ",[164,355,299],{"class":181},[164,357,302],{"class":188},[164,359,305],{"class":177},[164,361,308],{"class":188},[164,363,312],{"class":311},[164,365,305],{"class":177},[164,367,368],{"class":181},"dict",[164,370,320],{"class":188},[164,372,374],{"class":166,"line":373},18,[164,375,196],{"emptyLinePlaceholder":195},[164,377,379,382],{"class":166,"line":378},19,[164,380,381],{"class":268},"    @",[164,383,384],{"class":181},"property\n",[164,386,388,391,394,397,400],{"class":166,"line":387},20,[164,389,390],{"class":177},"    def",[164,392,393],{"class":268}," not_started",[164,395,396],{"class":188},"(self) -> ",[164,398,399],{"class":181},"int",[164,401,281],{"class":188},[164,403,405,408,411,414,417,420,423,426,429,431,433,435,437,440,442,444,446,448],{"class":166,"line":404},21,[164,406,407],{"class":177},"        return",[164,409,410],{"class":181}," self",[164,412,413],{"class":188},".total ",[164,415,416],{"class":177},"-",[164,418,419],{"class":181}," len",[164,421,422],{"class":188},"(",[164,424,425],{"class":181},"self",[164,427,428],{"class":188},".done) ",[164,430,416],{"class":177},[164,432,419],{"class":181},[164,434,422],{"class":188},[164,436,425],{"class":181},[164,438,439],{"class":188},".cancelled) ",[164,441,416],{"class":177},[164,443,419],{"class":181},[164,445,422],{"class":188},[164,447,425],{"class":181},[164,449,450],{"class":188},".failed)\n",[164,452,454],{"class":166,"line":453},22,[164,455,196],{"emptyLinePlaceholder":195},[164,457,459],{"class":166,"line":458},23,[164,460,196],{"emptyLinePlaceholder":195},[164,462,464,467,470,473,476,478,481,484],{"class":166,"line":463},24,[164,465,466],{"class":177},"async",[164,468,469],{"class":177}," def",[164,471,472],{"class":268}," fetch_one",[164,474,475],{"class":188},"(client: httpx.AsyncClient, url: ",[164,477,299],{"class":181},[164,479,480],{"class":188},", dest: Path, state: MirrorState) -> ",[164,482,483],{"class":181},"None",[164,485,281],{"class":188},[164,487,489,492,494,497,500,504],{"class":166,"line":488},25,[164,490,491],{"class":188},"    part ",[164,493,305],{"class":177},[164,495,496],{"class":188}," dest.with_name(dest.name ",[164,498,499],{"class":177},"+",[164,501,503],{"class":502},"sZZnC"," \".part\"",[164,505,320],{"class":188},[164,507,509,512],{"class":166,"line":508},26,[164,510,511],{"class":177},"    try",[164,513,281],{"class":188},[164,515,517,520,523,526,529,532,535],{"class":166,"line":516},27,[164,518,519],{"class":177},"        async",[164,521,522],{"class":177}," with",[164,524,525],{"class":188}," client.stream(",[164,527,528],{"class":502},"\"GET\"",[164,530,531],{"class":188},", url) ",[164,533,534],{"class":177},"as",[164,536,537],{"class":188}," response:\n",[164,539,541],{"class":166,"line":540},28,[164,542,543],{"class":188},"            response.raise_for_status()\n",[164,545,547,550,553,556,559,561],{"class":166,"line":546},29,[164,548,549],{"class":177},"            with",[164,551,552],{"class":188}," part.open(",[164,554,555],{"class":502},"\"wb\"",[164,557,558],{"class":188},") ",[164,560,534],{"class":177},[164,562,563],{"class":188}," fh:\n",[164,565,567,570,573,576,579,582,585,588,591],{"class":166,"line":566},30,[164,568,569],{"class":177},"                async",[164,571,572],{"class":177}," for",[164,574,575],{"class":188}," chunk ",[164,577,578],{"class":177},"in",[164,580,581],{"class":188}," response.aiter_bytes(",[164,583,584],{"class":181},"64",[164,586,587],{"class":177}," *",[164,589,590],{"class":181}," 1024",[164,592,593],{"class":188},"):\n",[164,595,597],{"class":166,"line":596},31,[164,598,599],{"class":188},"                    fh.write(chunk)\n",[164,601,603],{"class":166,"line":602},32,[164,604,605],{"class":170},"        # The rename is quick and must not be half-done: protect it from cancellation.\n",[164,607,609,612],{"class":166,"line":608},33,[164,610,611],{"class":177},"        await",[164,613,614],{"class":188}," asyncio.shield(asyncio.to_thread(os.replace, part, dest))\n",[164,616,618],{"class":166,"line":617},34,[164,619,620],{"class":188},"        state.done.append(url)\n",[164,622,624,627],{"class":166,"line":623},35,[164,625,626],{"class":177},"    except",[164,628,629],{"class":188}," asyncio.CancelledError:\n",[164,631,633],{"class":166,"line":632},36,[164,634,635],{"class":188},"        state.cancelled.append(url)\n",[164,637,639,642],{"class":166,"line":638},37,[164,640,641],{"class":177},"        raise",[164,643,644],{"class":170},"                                   # never swallow cancellation\n",[164,646,648,650,653,655],{"class":166,"line":647},38,[164,649,626],{"class":177},[164,651,652],{"class":188}," httpx.HTTPError ",[164,654,534],{"class":177},[164,656,657],{"class":188}," exc:\n",[164,659,661,664,666,669,672,675,678,681],{"class":166,"line":660},39,[164,662,663],{"class":188},"        state.failed[url] ",[164,665,305],{"class":177},[164,667,668],{"class":181}," str",[164,670,671],{"class":188},"(exc) ",[164,673,674],{"class":177},"or",[164,676,677],{"class":181}," type",[164,679,680],{"class":188},"(exc).",[164,682,683],{"class":181},"__name__\n",[164,685,687,690],{"class":166,"line":686},40,[164,688,689],{"class":177},"    finally",[164,691,281],{"class":188},[164,693,695,698,701,703,706,709],{"class":166,"line":694},41,[164,696,697],{"class":188},"        part.unlink(",[164,699,700],{"class":311},"missing_ok",[164,702,305],{"class":177},[164,704,705],{"class":181},"True",[164,707,708],{"class":188},")            ",[164,710,711],{"class":170},"# gone on success (renamed) or failure\n",[164,713,715],{"class":166,"line":714},42,[164,716,196],{"emptyLinePlaceholder":195},[164,718,720],{"class":166,"line":719},43,[164,721,196],{"emptyLinePlaceholder":195},[164,723,725,727,729,732,735,737,740,742,745,747],{"class":166,"line":724},44,[164,726,466],{"class":177},[164,728,469],{"class":177},[164,730,731],{"class":268}," mirror",[164,733,734],{"class":188},"(urls: list[",[164,736,299],{"class":181},[164,738,739],{"class":188},"], out: Path, jobs: ",[164,741,399],{"class":181},[164,743,744],{"class":188},", state: MirrorState) -> ",[164,746,483],{"class":181},[164,748,281],{"class":188},[164,750,752,755,757],{"class":166,"line":751},45,[164,753,754],{"class":188},"    sem ",[164,756,305],{"class":177},[164,758,759],{"class":188}," asyncio.Semaphore(jobs)\n",[164,761,763,766,769,771,773,775,778,780,782],{"class":166,"line":762},46,[164,764,765],{"class":188},"    out.mkdir(",[164,767,768],{"class":311},"parents",[164,770,305],{"class":177},[164,772,705],{"class":181},[164,774,353],{"class":188},[164,776,777],{"class":311},"exist_ok",[164,779,305],{"class":177},[164,781,705],{"class":181},[164,783,320],{"class":188},[164,785,787,790,792,795,798,800,803,806,808,811,813,816],{"class":166,"line":786},47,[164,788,789],{"class":177},"    async",[164,791,522],{"class":177},[164,793,794],{"class":188}," httpx.AsyncClient(",[164,796,797],{"class":311},"timeout",[164,799,305],{"class":177},[164,801,802],{"class":188},"httpx.Timeout(",[164,804,805],{"class":181},"30.0",[164,807,353],{"class":188},[164,809,810],{"class":311},"connect",[164,812,305],{"class":177},[164,814,815],{"class":181},"5.0",[164,817,818],{"class":188},"),\n",[164,820,822,825,827,829,831,833],{"class":166,"line":821},48,[164,823,824],{"class":311},"                                 follow_redirects",[164,826,305],{"class":177},[164,828,705],{"class":181},[164,830,558],{"class":188},[164,832,534],{"class":177},[164,834,835],{"class":188}," client:\n",[164,837,839],{"class":166,"line":838},49,[164,840,196],{"emptyLinePlaceholder":195},[164,842,844,846,848,851,854,856,859,861],{"class":166,"line":843},50,[164,845,519],{"class":177},[164,847,469],{"class":177},[164,849,850],{"class":268}," guarded",[164,852,853],{"class":188},"(url: ",[164,855,299],{"class":181},[164,857,858],{"class":188},") -> ",[164,860,483],{"class":181},[164,862,281],{"class":188},[164,864,866,869,871],{"class":166,"line":865},51,[164,867,868],{"class":177},"            async",[164,870,522],{"class":177},[164,872,873],{"class":188}," sem:\n",[164,875,877,880,882,885,888,890,893,896,898,900,902,904],{"class":166,"line":876},52,[164,878,879],{"class":188},"                name ",[164,881,305],{"class":177},[164,883,884],{"class":188}," httpx.URL(url).path.rsplit(",[164,886,887],{"class":502},"\"\u002F\"",[164,889,353],{"class":188},[164,891,892],{"class":181},"1",[164,894,895],{"class":188},")[",[164,897,416],{"class":177},[164,899,892],{"class":181},[164,901,302],{"class":188},[164,903,674],{"class":177},[164,905,906],{"class":502}," \"index.html\"\n",[164,908,910,913,916,919],{"class":166,"line":909},53,[164,911,912],{"class":177},"                await",[164,914,915],{"class":188}," fetch_one(client, url, out ",[164,917,918],{"class":177},"\u002F",[164,920,921],{"class":188}," name, state)\n",[164,923,925],{"class":166,"line":924},54,[164,926,196],{"emptyLinePlaceholder":195},[164,928,930,932,934,937,939],{"class":166,"line":929},55,[164,931,519],{"class":177},[164,933,522],{"class":177},[164,935,936],{"class":188}," asyncio.TaskGroup() ",[164,938,534],{"class":177},[164,940,941],{"class":188}," tg:\n",[164,943,945,948,951,953],{"class":166,"line":944},56,[164,946,947],{"class":177},"            for",[164,949,950],{"class":188}," url ",[164,952,578],{"class":177},[164,954,955],{"class":188}," urls:\n",[164,957,959],{"class":166,"line":958},57,[164,960,961],{"class":188},"                tg.create_task(guarded(url))\n",[155,963,965],{"className":157,"code":964,"language":159,"meta":160,"style":160},"# src\u002Fmytool\u002Fcli.py\nimport asyncio\nfrom pathlib import Path\n\nimport typer\n\nfrom mytool.mirror import MirrorState, mirror\n\napp = typer.Typer()\n\n\n@app.callback()\ndef main() -> None:\n    \"\"\"Mirroring tools.\"\"\"\n\n\n@app.command(\"mirror\")\ndef mirror_cmd(\n    urls_file: typer.FileText,\n    out: Path = typer.Option(Path(\"mirror\"), \"--out\", \"-o\"),\n    jobs: int = typer.Option(8, \"--jobs\", \"-j\", min=1, max=64),\n) -> None:\n    \"\"\"Download every URL listed in URLS_FILE.\"\"\"\n    urls = [u.strip() for u in urls_file if u.strip()]\n    state = MirrorState(total=len(urls))\n    try:\n        asyncio.run(mirror(urls, out, jobs, state))\n    except KeyboardInterrupt:\n        typer.echo(\n            f\"\\ninterrupted: {len(state.done)} done, {len(state.cancelled)} cancelled, \"\n            f\"{state.not_started} not started\",\n            err=True,\n        )\n        typer.echo(\"partial files removed; re-run to continue\", err=True)\n        raise typer.Exit(130)\n    for url, why in state.failed.items():\n        typer.echo(f\"✗ {url}: {why}\", err=True)\n    typer.echo(f\"mirrored {len(state.done)}\u002F{state.total}\", err=True)\n    raise typer.Exit(1 if state.failed else 0)\n\n\nif __name__ == \"__main__\":\n    app()\n",[14,966,967,972,978,988,992,999,1003,1015,1019,1029,1033,1037,1045,1060,1065,1069,1073,1085,1095,1100,1125,1171,1179,1184,1211,1232,1238,1243,1252,1257,1293,1313,1324,1329,1348,1360,1373,1412,1449,1472,1476,1480,1495],{"__ignoreMap":160},[164,968,969],{"class":166,"line":167},[164,970,971],{"class":170},"# src\u002Fmytool\u002Fcli.py\n",[164,973,974,976],{"class":166,"line":174},[164,975,202],{"class":177},[164,977,205],{"class":188},[164,979,980,982,984,986],{"class":166,"line":192},[164,981,178],{"class":177},[164,983,234],{"class":188},[164,985,202],{"class":177},[164,987,239],{"class":188},[164,989,990],{"class":166,"line":199},[164,991,196],{"emptyLinePlaceholder":195},[164,993,994,996],{"class":166,"line":208},[164,995,202],{"class":177},[164,997,998],{"class":188}," typer\n",[164,1000,1001],{"class":166,"line":216},[164,1002,196],{"emptyLinePlaceholder":195},[164,1004,1005,1007,1010,1012],{"class":166,"line":229},[164,1006,178],{"class":177},[164,1008,1009],{"class":188}," mytool.mirror ",[164,1011,202],{"class":177},[164,1013,1014],{"class":188}," MirrorState, mirror\n",[164,1016,1017],{"class":166,"line":242},[164,1018,196],{"emptyLinePlaceholder":195},[164,1020,1021,1024,1026],{"class":166,"line":247},[164,1022,1023],{"class":188},"app ",[164,1025,305],{"class":177},[164,1027,1028],{"class":188}," typer.Typer()\n",[164,1030,1031],{"class":166,"line":255},[164,1032,196],{"emptyLinePlaceholder":195},[164,1034,1035],{"class":166,"line":260},[164,1036,196],{"emptyLinePlaceholder":195},[164,1038,1039,1042],{"class":166,"line":265},[164,1040,1041],{"class":268},"@app.callback",[164,1043,1044],{"class":188},"()\n",[164,1046,1047,1050,1053,1056,1058],{"class":166,"line":272},[164,1048,1049],{"class":177},"def",[164,1051,1052],{"class":268}," main",[164,1054,1055],{"class":188},"() -> ",[164,1057,483],{"class":181},[164,1059,281],{"class":188},[164,1061,1062],{"class":166,"line":284},[164,1063,1064],{"class":502},"    \"\"\"Mirroring tools.\"\"\"\n",[164,1066,1067],{"class":166,"line":293},[164,1068,196],{"emptyLinePlaceholder":195},[164,1070,1071],{"class":166,"line":323},[164,1072,196],{"emptyLinePlaceholder":195},[164,1074,1075,1078,1080,1083],{"class":166,"line":345},[164,1076,1077],{"class":268},"@app.command",[164,1079,422],{"class":188},[164,1081,1082],{"class":502},"\"mirror\"",[164,1084,320],{"class":188},[164,1086,1087,1089,1092],{"class":166,"line":373},[164,1088,1049],{"class":177},[164,1090,1091],{"class":268}," mirror_cmd",[164,1093,1094],{"class":188},"(\n",[164,1096,1097],{"class":166,"line":378},[164,1098,1099],{"class":188},"    urls_file: typer.FileText,\n",[164,1101,1102,1105,1107,1110,1112,1115,1118,1120,1123],{"class":166,"line":387},[164,1103,1104],{"class":188},"    out: Path ",[164,1106,305],{"class":177},[164,1108,1109],{"class":188}," typer.Option(Path(",[164,1111,1082],{"class":502},[164,1113,1114],{"class":188},"), ",[164,1116,1117],{"class":502},"\"--out\"",[164,1119,353],{"class":188},[164,1121,1122],{"class":502},"\"-o\"",[164,1124,818],{"class":188},[164,1126,1127,1130,1132,1135,1138,1141,1143,1146,1148,1151,1153,1156,1158,1160,1162,1165,1167,1169],{"class":166,"line":404},[164,1128,1129],{"class":188},"    jobs: ",[164,1131,399],{"class":181},[164,1133,1134],{"class":177}," =",[164,1136,1137],{"class":188}," typer.Option(",[164,1139,1140],{"class":181},"8",[164,1142,353],{"class":188},[164,1144,1145],{"class":502},"\"--jobs\"",[164,1147,353],{"class":188},[164,1149,1150],{"class":502},"\"-j\"",[164,1152,353],{"class":188},[164,1154,1155],{"class":311},"min",[164,1157,305],{"class":177},[164,1159,892],{"class":181},[164,1161,353],{"class":188},[164,1163,1164],{"class":311},"max",[164,1166,305],{"class":177},[164,1168,584],{"class":181},[164,1170,818],{"class":188},[164,1172,1173,1175,1177],{"class":166,"line":453},[164,1174,858],{"class":188},[164,1176,483],{"class":181},[164,1178,281],{"class":188},[164,1180,1181],{"class":166,"line":458},[164,1182,1183],{"class":502},"    \"\"\"Download every URL listed in URLS_FILE.\"\"\"\n",[164,1185,1186,1189,1191,1194,1197,1200,1202,1205,1208],{"class":166,"line":463},[164,1187,1188],{"class":188},"    urls ",[164,1190,305],{"class":177},[164,1192,1193],{"class":188}," [u.strip() ",[164,1195,1196],{"class":177},"for",[164,1198,1199],{"class":188}," u ",[164,1201,578],{"class":177},[164,1203,1204],{"class":188}," urls_file ",[164,1206,1207],{"class":177},"if",[164,1209,1210],{"class":188}," u.strip()]\n",[164,1212,1213,1216,1218,1221,1224,1226,1229],{"class":166,"line":488},[164,1214,1215],{"class":188},"    state ",[164,1217,305],{"class":177},[164,1219,1220],{"class":188}," MirrorState(",[164,1222,1223],{"class":311},"total",[164,1225,305],{"class":177},[164,1227,1228],{"class":181},"len",[164,1230,1231],{"class":188},"(urls))\n",[164,1233,1234,1236],{"class":166,"line":508},[164,1235,511],{"class":177},[164,1237,281],{"class":188},[164,1239,1240],{"class":166,"line":516},[164,1241,1242],{"class":188},"        asyncio.run(mirror(urls, out, jobs, state))\n",[164,1244,1245,1247,1250],{"class":166,"line":540},[164,1246,626],{"class":177},[164,1248,1249],{"class":181}," KeyboardInterrupt",[164,1251,281],{"class":188},[164,1253,1254],{"class":166,"line":546},[164,1255,1256],{"class":188},"        typer.echo(\n",[164,1258,1259,1262,1265,1268,1271,1274,1277,1280,1283,1285,1288,1290],{"class":166,"line":566},[164,1260,1261],{"class":177},"            f",[164,1263,1264],{"class":502},"\"",[164,1266,1267],{"class":181},"\\n",[164,1269,1270],{"class":502},"interrupted: ",[164,1272,1273],{"class":181},"{len",[164,1275,1276],{"class":188},"(state.done)",[164,1278,1279],{"class":181},"}",[164,1281,1282],{"class":502}," done, ",[164,1284,1273],{"class":181},[164,1286,1287],{"class":188},"(state.cancelled)",[164,1289,1279],{"class":181},[164,1291,1292],{"class":502}," cancelled, \"\n",[164,1294,1295,1297,1299,1302,1305,1307,1310],{"class":166,"line":596},[164,1296,1261],{"class":177},[164,1298,1264],{"class":502},[164,1300,1301],{"class":181},"{",[164,1303,1304],{"class":188},"state.not_started",[164,1306,1279],{"class":181},[164,1308,1309],{"class":502}," not started\"",[164,1311,1312],{"class":188},",\n",[164,1314,1315,1318,1320,1322],{"class":166,"line":602},[164,1316,1317],{"class":311},"            err",[164,1319,305],{"class":177},[164,1321,705],{"class":181},[164,1323,1312],{"class":188},[164,1325,1326],{"class":166,"line":608},[164,1327,1328],{"class":188},"        )\n",[164,1330,1331,1334,1337,1339,1342,1344,1346],{"class":166,"line":617},[164,1332,1333],{"class":188},"        typer.echo(",[164,1335,1336],{"class":502},"\"partial files removed; re-run to continue\"",[164,1338,353],{"class":188},[164,1340,1341],{"class":311},"err",[164,1343,305],{"class":177},[164,1345,705],{"class":181},[164,1347,320],{"class":188},[164,1349,1350,1352,1355,1358],{"class":166,"line":623},[164,1351,641],{"class":177},[164,1353,1354],{"class":188}," typer.Exit(",[164,1356,1357],{"class":181},"130",[164,1359,320],{"class":188},[164,1361,1362,1365,1368,1370],{"class":166,"line":632},[164,1363,1364],{"class":177},"    for",[164,1366,1367],{"class":188}," url, why ",[164,1369,578],{"class":177},[164,1371,1372],{"class":188}," state.failed.items():\n",[164,1374,1375,1377,1380,1383,1385,1388,1390,1393,1395,1398,1400,1402,1404,1406,1408,1410],{"class":166,"line":638},[164,1376,1333],{"class":188},[164,1378,1379],{"class":177},"f",[164,1381,1382],{"class":502},"\"✗ ",[164,1384,1301],{"class":181},[164,1386,1387],{"class":188},"url",[164,1389,1279],{"class":181},[164,1391,1392],{"class":502},": ",[164,1394,1301],{"class":181},[164,1396,1397],{"class":188},"why",[164,1399,1279],{"class":181},[164,1401,1264],{"class":502},[164,1403,353],{"class":188},[164,1405,1341],{"class":311},[164,1407,305],{"class":177},[164,1409,705],{"class":181},[164,1411,320],{"class":188},[164,1413,1414,1417,1419,1422,1424,1426,1428,1430,1432,1435,1437,1439,1441,1443,1445,1447],{"class":166,"line":647},[164,1415,1416],{"class":188},"    typer.echo(",[164,1418,1379],{"class":177},[164,1420,1421],{"class":502},"\"mirrored ",[164,1423,1273],{"class":181},[164,1425,1276],{"class":188},[164,1427,1279],{"class":181},[164,1429,918],{"class":502},[164,1431,1301],{"class":181},[164,1433,1434],{"class":188},"state.total",[164,1436,1279],{"class":181},[164,1438,1264],{"class":502},[164,1440,353],{"class":188},[164,1442,1341],{"class":311},[164,1444,305],{"class":177},[164,1446,705],{"class":181},[164,1448,320],{"class":188},[164,1450,1451,1454,1456,1458,1461,1464,1467,1470],{"class":166,"line":660},[164,1452,1453],{"class":177},"    raise",[164,1455,1354],{"class":188},[164,1457,892],{"class":181},[164,1459,1460],{"class":177}," if",[164,1462,1463],{"class":188}," state.failed ",[164,1465,1466],{"class":177},"else",[164,1468,1469],{"class":181}," 0",[164,1471,320],{"class":188},[164,1473,1474],{"class":166,"line":686},[164,1475,196],{"emptyLinePlaceholder":195},[164,1477,1478],{"class":166,"line":694},[164,1479,196],{"emptyLinePlaceholder":195},[164,1481,1482,1484,1487,1490,1493],{"class":166,"line":714},[164,1483,1207],{"class":177},[164,1485,1486],{"class":181}," __name__",[164,1488,1489],{"class":177}," ==",[164,1491,1492],{"class":502}," \"__main__\"",[164,1494,281],{"class":188},[164,1496,1497],{"class":166,"line":719},[164,1498,1499],{"class":188},"    app()\n",[1501,1502,1504],"h3",{"id":1503},"why-each-piece-is-there","Why each piece is there",[10,1506,1507,1512,1513,1515,1516,1518,1519,1522,1523,1525,1526,1529,1530,1533],{},[93,1508,1509,35],{},[14,1510,1511],{},"except asyncio.CancelledError: ... raise"," Recording the cancellation is fine; swallowing it is not. If a task catches ",[14,1514,20],{}," and returns normally, the task group believes it finished, and the cancellation that was meant to stop the program is lost — the classic \"Ctrl+C does nothing\" bug. Since Python 3.8, ",[14,1517,20],{}," inherits from ",[14,1520,1521],{},"BaseException",", so ",[14,1524,24],{}," no longer catches it by accident; bare ",[14,1527,1528],{},"except:"," and ",[14,1531,1532],{},"except BaseException:"," still do.",[10,1535,1536,1541,1542,1545,1546,35],{},[93,1537,1538,1539,35],{},"Cleanup in ",[14,1540,119],{}," The partial file is removed whether the download succeeded (it was renamed, so ",[14,1543,1544],{},"unlink"," is a no-op), failed, or was cancelled. Anything that must happen on every exit path belongs there, or in an ",[14,1547,123],{},[10,1549,1550,1556,1557,1559],{},[93,1551,1552,1555],{},[14,1553,1554],{},"asyncio.shield"," for a short critical section."," Shielding protects an awaitable from cancellation so it runs to completion, while the surrounding task still sees the ",[14,1558,20],{},". Use it only for brief, essential steps — here, the rename that makes a finished download visible. Shielding long operations defeats the purpose of Ctrl+C.",[10,1561,1562,1565,1566,1569],{},[93,1563,1564],{},"HTTP errors are data, cancellation is control flow."," ",[14,1567,1568],{},"httpx.HTTPError"," is recorded per URL and the task returns normally, so one bad URL does not cancel the others. Only cancellation and unexpected bugs propagate through the task group.",[104,1571],{"name":1572},"cc-cancel-rules",[1501,1574,1576],{"id":1575},"bounding-shutdown-time","Bounding shutdown time",[10,1578,1579],{},"Cleanup that awaits the network — closing connections, notifying a server that a job was aborted — can itself hang. Wrap it in a timeout so Ctrl+C always ends the program promptly:",[155,1581,1583],{"className":157,"code":1582,"language":159,"meta":160,"style":160},"async def notify_aborted(client, job_id: str) -> None:\n    try:\n        async with asyncio.timeout(2):\n            await client.post(f\"\u002Fjobs\u002F{job_id}\u002Fabort\")\n    except (TimeoutError, httpx.HTTPError):\n        pass   # best effort: never block shutdown on a courtesy call\n",[14,1584,1585,1605,1611,1625,1650,1663],{"__ignoreMap":160},[164,1586,1587,1589,1591,1594,1597,1599,1601,1603],{"class":166,"line":167},[164,1588,466],{"class":177},[164,1590,469],{"class":177},[164,1592,1593],{"class":268}," notify_aborted",[164,1595,1596],{"class":188},"(client, job_id: ",[164,1598,299],{"class":181},[164,1600,858],{"class":188},[164,1602,483],{"class":181},[164,1604,281],{"class":188},[164,1606,1607,1609],{"class":166,"line":174},[164,1608,511],{"class":177},[164,1610,281],{"class":188},[164,1612,1613,1615,1617,1620,1623],{"class":166,"line":192},[164,1614,519],{"class":177},[164,1616,522],{"class":177},[164,1618,1619],{"class":188}," asyncio.timeout(",[164,1621,1622],{"class":181},"2",[164,1624,593],{"class":188},[164,1626,1627,1630,1633,1635,1638,1640,1643,1645,1648],{"class":166,"line":199},[164,1628,1629],{"class":177},"            await",[164,1631,1632],{"class":188}," client.post(",[164,1634,1379],{"class":177},[164,1636,1637],{"class":502},"\"\u002Fjobs\u002F",[164,1639,1301],{"class":181},[164,1641,1642],{"class":188},"job_id",[164,1644,1279],{"class":181},[164,1646,1647],{"class":502},"\u002Fabort\"",[164,1649,320],{"class":188},[164,1651,1652,1654,1657,1660],{"class":166,"line":208},[164,1653,626],{"class":177},[164,1655,1656],{"class":188}," (",[164,1658,1659],{"class":181},"TimeoutError",[164,1661,1662],{"class":188},", httpx.HTTPError):\n",[164,1664,1665,1668],{"class":166,"line":216},[164,1666,1667],{"class":177},"        pass",[164,1669,1670],{"class":170},"   # best effort: never block shutdown on a courtesy call\n",[10,1672,1673],{},"The user's second Ctrl+C is the final backstop, but a tool that needs it has already disappointed them.",[37,1675,1677],{"id":1676},"ux-considerations","UX considerations",[104,1679],{"name":1680},"cc-cancel-terminal",[42,1682,1683,1689,1695,1705,1717],{},[45,1684,1685,1688],{},[93,1686,1687],{},"Report the state you left things in."," \"37 done, 8 cancelled, 75 not started\" tells the user exactly what a re-run will do. Keep the counts in a state object outside the coroutine so they survive the interrupt.",[45,1690,1691,1694],{},[93,1692,1693],{},"Make re-running safe."," Because partial files are always removed and complete ones are renamed atomically, a second run can skip what exists and fetch the rest.",[45,1696,1697,1700,1701,1704],{},[93,1698,1699],{},"Exit with 130."," By convention, ",[14,1702,1703],{},"128 + SIGINT(2)",". Shells and CI systems recognise it as \"interrupted\", not \"failed\".",[45,1706,1707,1710,1711,1713,1714,1716],{},[93,1708,1709],{},"No tracebacks for Ctrl+C."," Catch ",[14,1712,83],{}," around ",[14,1715,50],{}," and print one line. A traceback on an intentional interrupt looks like a crash.",[45,1718,1719,1565,1726,1728,1729,1731,1732,1734,1735,1738,1739,35],{},[93,1720,1721,1722,1725],{},"Respect ",[14,1723,1724],{},"SIGTERM"," too.",[14,1727,50],{}," only handles ",[14,1730,79],{},". Under a supervisor, container runtime or CI timeout, you get ",[14,1733,1724],{},"; add a handler with ",[14,1736,1737],{},"loop.add_signal_handler(signal.SIGTERM, main_task.cancel)"," on POSIX so it gets the same clean shutdown — see ",[31,1740,1742],{"href":1741},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown\u002F","handling SIGTERM and graceful shutdown",[37,1744,1746],{"id":1745},"testing-the-behaviour","Testing the behaviour",[10,1748,1749,1750,1752,1753,1529,1756,1759],{},"Cancellation logic is testable without signals: cancel the task yourself and assert on the aftermath. For the full path — a real ",[14,1751,79],{}," to a real process — one integration test using ",[14,1754,1755],{},"subprocess",[14,1757,1758],{},"send_signal"," is worth having on POSIX:",[155,1761,1763],{"className":157,"code":1762,"language":159,"meta":160,"style":160},"# tests\u002Ftest_cancel.py\nimport asyncio\nimport sys\n\nimport httpx\nimport pytest\n\nfrom mytool import mirror as m\n\n\ndef slow_server(delay_for: set[str]):\n    async def handler(request):\n        if request.url.path in delay_for:\n            await asyncio.sleep(10)\n        return httpx.Response(200, content=b\"x\" * 1000)\n    return httpx.MockTransport(handler)\n\n\n@pytest.fixture\ndef patched_client(monkeypatch):\n    def install(transport):\n        real = httpx.AsyncClient\n        monkeypatch.setattr(m.httpx, \"AsyncClient\", lambda **kw: real(transport=transport, **kw))\n    return install\n\n\ndef test_cancel_cleans_up_and_records(tmp_path, patched_client):\n    patched_client(slow_server({\"\u002Fb.bin\", \"\u002Fc.bin\"}))\n    urls = [f\"https:\u002F\u002Ffiles.test\u002F{n}.bin\" for n in \"abc\"]\n    state = m.MirrorState(total=3)\n\n    async def scenario():\n        task = asyncio.create_task(m.mirror(urls, tmp_path, 3, state))\n        await asyncio.sleep(0.2)          # let a.bin finish, b and c hang\n        task.cancel()\n        with pytest.raises(asyncio.CancelledError):\n            await task\n\n    asyncio.run(scenario())\n    assert state.done == [\"https:\u002F\u002Ffiles.test\u002Fa.bin\"]\n    assert sorted(state.cancelled) == [\"https:\u002F\u002Ffiles.test\u002Fb.bin\", \"https:\u002F\u002Ffiles.test\u002Fc.bin\"]\n    assert sorted(p.name for p in tmp_path.iterdir()) == [\"a.bin\"]   # no .part files\n\n\n@pytest.mark.skipif(sys.platform == \"win32\", reason=\"POSIX signals\")\ndef test_real_sigint_exits_130(tmp_path):\n    import signal\n    import subprocess\n    import textwrap\n    import time\n\n    script = tmp_path \u002F \"prog.py\"\n    script.write_text(textwrap.dedent(\"\"\"\n        import asyncio, sys\n        async def main():\n            try:\n                await asyncio.sleep(30)\n            finally:\n                print(\"cleaned up\", flush=True)\n        try:\n            asyncio.run(main())\n        except KeyboardInterrupt:\n            sys.exit(130)\n    \"\"\"))\n    proc = subprocess.Popen([sys.executable, str(script)], stdout=subprocess.PIPE, text=True)\n    time.sleep(0.5)\n    proc.send_signal(signal.SIGINT)\n    out, _ = proc.communicate(timeout=5)\n    assert proc.returncode == 130\n    assert \"cleaned up\" in out\n",[14,1764,1765,1770,1776,1783,1787,1793,1800,1804,1821,1825,1829,1844,1856,1869,1881,1911,1919,1923,1927,1932,1942,1952,1962,1995,2002,2006,2010,2020,2036,2073,2091,2095,2107,2122,2137,2142,2150,2157,2161,2166,2184,2208,2240,2244,2248,2273,2283,2291,2298,2305,2312,2316,2331,2339,2344,2349,2354,2359,2365,2371,2377,2383,2389,2395,2404,2442,2453,2463,2483,2496],{"__ignoreMap":160},[164,1766,1767],{"class":166,"line":167},[164,1768,1769],{"class":170},"# tests\u002Ftest_cancel.py\n",[164,1771,1772,1774],{"class":166,"line":174},[164,1773,202],{"class":177},[164,1775,205],{"class":188},[164,1777,1778,1780],{"class":166,"line":192},[164,1779,202],{"class":177},[164,1781,1782],{"class":188}," sys\n",[164,1784,1785],{"class":166,"line":199},[164,1786,196],{"emptyLinePlaceholder":195},[164,1788,1789,1791],{"class":166,"line":208},[164,1790,202],{"class":177},[164,1792,252],{"class":188},[164,1794,1795,1797],{"class":166,"line":216},[164,1796,202],{"class":177},[164,1798,1799],{"class":188}," pytest\n",[164,1801,1802],{"class":166,"line":229},[164,1803,196],{"emptyLinePlaceholder":195},[164,1805,1806,1808,1811,1813,1816,1818],{"class":166,"line":242},[164,1807,178],{"class":177},[164,1809,1810],{"class":188}," mytool ",[164,1812,202],{"class":177},[164,1814,1815],{"class":188}," mirror ",[164,1817,534],{"class":177},[164,1819,1820],{"class":188}," m\n",[164,1822,1823],{"class":166,"line":247},[164,1824,196],{"emptyLinePlaceholder":195},[164,1826,1827],{"class":166,"line":255},[164,1828,196],{"emptyLinePlaceholder":195},[164,1830,1831,1833,1836,1839,1841],{"class":166,"line":260},[164,1832,1049],{"class":177},[164,1834,1835],{"class":268}," slow_server",[164,1837,1838],{"class":188},"(delay_for: set[",[164,1840,299],{"class":181},[164,1842,1843],{"class":188},"]):\n",[164,1845,1846,1848,1850,1853],{"class":166,"line":265},[164,1847,789],{"class":177},[164,1849,469],{"class":177},[164,1851,1852],{"class":268}," handler",[164,1854,1855],{"class":188},"(request):\n",[164,1857,1858,1861,1864,1866],{"class":166,"line":272},[164,1859,1860],{"class":177},"        if",[164,1862,1863],{"class":188}," request.url.path ",[164,1865,578],{"class":177},[164,1867,1868],{"class":188}," delay_for:\n",[164,1870,1871,1873,1876,1879],{"class":166,"line":284},[164,1872,1629],{"class":177},[164,1874,1875],{"class":188}," asyncio.sleep(",[164,1877,1878],{"class":181},"10",[164,1880,320],{"class":188},[164,1882,1883,1885,1888,1891,1893,1896,1898,1901,1904,1906,1909],{"class":166,"line":293},[164,1884,407],{"class":177},[164,1886,1887],{"class":188}," httpx.Response(",[164,1889,1890],{"class":181},"200",[164,1892,353],{"class":188},[164,1894,1895],{"class":311},"content",[164,1897,305],{"class":177},[164,1899,1900],{"class":177},"b",[164,1902,1903],{"class":502},"\"x\"",[164,1905,587],{"class":177},[164,1907,1908],{"class":181}," 1000",[164,1910,320],{"class":188},[164,1912,1913,1916],{"class":166,"line":323},[164,1914,1915],{"class":177},"    return",[164,1917,1918],{"class":188}," httpx.MockTransport(handler)\n",[164,1920,1921],{"class":166,"line":345},[164,1922,196],{"emptyLinePlaceholder":195},[164,1924,1925],{"class":166,"line":373},[164,1926,196],{"emptyLinePlaceholder":195},[164,1928,1929],{"class":166,"line":378},[164,1930,1931],{"class":268},"@pytest.fixture\n",[164,1933,1934,1936,1939],{"class":166,"line":387},[164,1935,1049],{"class":177},[164,1937,1938],{"class":268}," patched_client",[164,1940,1941],{"class":188},"(monkeypatch):\n",[164,1943,1944,1946,1949],{"class":166,"line":404},[164,1945,390],{"class":177},[164,1947,1948],{"class":268}," install",[164,1950,1951],{"class":188},"(transport):\n",[164,1953,1954,1957,1959],{"class":166,"line":453},[164,1955,1956],{"class":188},"        real ",[164,1958,305],{"class":177},[164,1960,1961],{"class":188}," httpx.AsyncClient\n",[164,1963,1964,1967,1970,1972,1975,1978,1981,1984,1986,1989,1992],{"class":166,"line":458},[164,1965,1966],{"class":188},"        monkeypatch.setattr(m.httpx, ",[164,1968,1969],{"class":502},"\"AsyncClient\"",[164,1971,353],{"class":188},[164,1973,1974],{"class":177},"lambda",[164,1976,1977],{"class":177}," **",[164,1979,1980],{"class":188},"kw: real(",[164,1982,1983],{"class":311},"transport",[164,1985,305],{"class":177},[164,1987,1988],{"class":188},"transport, ",[164,1990,1991],{"class":177},"**",[164,1993,1994],{"class":188},"kw))\n",[164,1996,1997,1999],{"class":166,"line":463},[164,1998,1915],{"class":177},[164,2000,2001],{"class":188}," install\n",[164,2003,2004],{"class":166,"line":488},[164,2005,196],{"emptyLinePlaceholder":195},[164,2007,2008],{"class":166,"line":508},[164,2009,196],{"emptyLinePlaceholder":195},[164,2011,2012,2014,2017],{"class":166,"line":516},[164,2013,1049],{"class":177},[164,2015,2016],{"class":268}," test_cancel_cleans_up_and_records",[164,2018,2019],{"class":188},"(tmp_path, patched_client):\n",[164,2021,2022,2025,2028,2030,2033],{"class":166,"line":540},[164,2023,2024],{"class":188},"    patched_client(slow_server({",[164,2026,2027],{"class":502},"\"\u002Fb.bin\"",[164,2029,353],{"class":188},[164,2031,2032],{"class":502},"\"\u002Fc.bin\"",[164,2034,2035],{"class":188},"}))\n",[164,2037,2038,2040,2042,2045,2047,2050,2052,2055,2057,2060,2062,2065,2067,2070],{"class":166,"line":546},[164,2039,1188],{"class":188},[164,2041,305],{"class":177},[164,2043,2044],{"class":188}," [",[164,2046,1379],{"class":177},[164,2048,2049],{"class":502},"\"https:\u002F\u002Ffiles.test\u002F",[164,2051,1301],{"class":181},[164,2053,2054],{"class":188},"n",[164,2056,1279],{"class":181},[164,2058,2059],{"class":502},".bin\"",[164,2061,572],{"class":177},[164,2063,2064],{"class":188}," n ",[164,2066,578],{"class":177},[164,2068,2069],{"class":502}," \"abc\"",[164,2071,2072],{"class":188},"]\n",[164,2074,2075,2077,2079,2082,2084,2086,2089],{"class":166,"line":566},[164,2076,1215],{"class":188},[164,2078,305],{"class":177},[164,2080,2081],{"class":188}," m.MirrorState(",[164,2083,1223],{"class":311},[164,2085,305],{"class":177},[164,2087,2088],{"class":181},"3",[164,2090,320],{"class":188},[164,2092,2093],{"class":166,"line":596},[164,2094,196],{"emptyLinePlaceholder":195},[164,2096,2097,2099,2101,2104],{"class":166,"line":602},[164,2098,789],{"class":177},[164,2100,469],{"class":177},[164,2102,2103],{"class":268}," scenario",[164,2105,2106],{"class":188},"():\n",[164,2108,2109,2112,2114,2117,2119],{"class":166,"line":608},[164,2110,2111],{"class":188},"        task ",[164,2113,305],{"class":177},[164,2115,2116],{"class":188}," asyncio.create_task(m.mirror(urls, tmp_path, ",[164,2118,2088],{"class":181},[164,2120,2121],{"class":188},", state))\n",[164,2123,2124,2126,2128,2131,2134],{"class":166,"line":617},[164,2125,611],{"class":177},[164,2127,1875],{"class":188},[164,2129,2130],{"class":181},"0.2",[164,2132,2133],{"class":188},")          ",[164,2135,2136],{"class":170},"# let a.bin finish, b and c hang\n",[164,2138,2139],{"class":166,"line":623},[164,2140,2141],{"class":188},"        task.cancel()\n",[164,2143,2144,2147],{"class":166,"line":632},[164,2145,2146],{"class":177},"        with",[164,2148,2149],{"class":188}," pytest.raises(asyncio.CancelledError):\n",[164,2151,2152,2154],{"class":166,"line":638},[164,2153,1629],{"class":177},[164,2155,2156],{"class":188}," task\n",[164,2158,2159],{"class":166,"line":647},[164,2160,196],{"emptyLinePlaceholder":195},[164,2162,2163],{"class":166,"line":660},[164,2164,2165],{"class":188},"    asyncio.run(scenario())\n",[164,2167,2168,2171,2174,2177,2179,2182],{"class":166,"line":686},[164,2169,2170],{"class":177},"    assert",[164,2172,2173],{"class":188}," state.done ",[164,2175,2176],{"class":177},"==",[164,2178,2044],{"class":188},[164,2180,2181],{"class":502},"\"https:\u002F\u002Ffiles.test\u002Fa.bin\"",[164,2183,2072],{"class":188},[164,2185,2186,2188,2191,2194,2196,2198,2201,2203,2206],{"class":166,"line":694},[164,2187,2170],{"class":177},[164,2189,2190],{"class":181}," sorted",[164,2192,2193],{"class":188},"(state.cancelled) ",[164,2195,2176],{"class":177},[164,2197,2044],{"class":188},[164,2199,2200],{"class":502},"\"https:\u002F\u002Ffiles.test\u002Fb.bin\"",[164,2202,353],{"class":188},[164,2204,2205],{"class":502},"\"https:\u002F\u002Ffiles.test\u002Fc.bin\"",[164,2207,2072],{"class":188},[164,2209,2210,2212,2214,2217,2219,2222,2224,2227,2229,2231,2234,2237],{"class":166,"line":714},[164,2211,2170],{"class":177},[164,2213,2190],{"class":181},[164,2215,2216],{"class":188},"(p.name ",[164,2218,1196],{"class":177},[164,2220,2221],{"class":188}," p ",[164,2223,578],{"class":177},[164,2225,2226],{"class":188}," tmp_path.iterdir()) ",[164,2228,2176],{"class":177},[164,2230,2044],{"class":188},[164,2232,2233],{"class":502},"\"a.bin\"",[164,2235,2236],{"class":188},"]   ",[164,2238,2239],{"class":170},"# no .part files\n",[164,2241,2242],{"class":166,"line":719},[164,2243,196],{"emptyLinePlaceholder":195},[164,2245,2246],{"class":166,"line":724},[164,2247,196],{"emptyLinePlaceholder":195},[164,2249,2250,2253,2256,2258,2261,2263,2266,2268,2271],{"class":166,"line":751},[164,2251,2252],{"class":268},"@pytest.mark.skipif",[164,2254,2255],{"class":188},"(sys.platform ",[164,2257,2176],{"class":177},[164,2259,2260],{"class":502}," \"win32\"",[164,2262,353],{"class":188},[164,2264,2265],{"class":311},"reason",[164,2267,305],{"class":177},[164,2269,2270],{"class":502},"\"POSIX signals\"",[164,2272,320],{"class":188},[164,2274,2275,2277,2280],{"class":166,"line":762},[164,2276,1049],{"class":177},[164,2278,2279],{"class":268}," test_real_sigint_exits_130",[164,2281,2282],{"class":188},"(tmp_path):\n",[164,2284,2285,2288],{"class":166,"line":786},[164,2286,2287],{"class":177},"    import",[164,2289,2290],{"class":188}," signal\n",[164,2292,2293,2295],{"class":166,"line":821},[164,2294,2287],{"class":177},[164,2296,2297],{"class":188}," subprocess\n",[164,2299,2300,2302],{"class":166,"line":838},[164,2301,2287],{"class":177},[164,2303,2304],{"class":188}," textwrap\n",[164,2306,2307,2309],{"class":166,"line":843},[164,2308,2287],{"class":177},[164,2310,2311],{"class":188}," time\n",[164,2313,2314],{"class":166,"line":865},[164,2315,196],{"emptyLinePlaceholder":195},[164,2317,2318,2321,2323,2326,2328],{"class":166,"line":876},[164,2319,2320],{"class":188},"    script ",[164,2322,305],{"class":177},[164,2324,2325],{"class":188}," tmp_path ",[164,2327,918],{"class":177},[164,2329,2330],{"class":502}," \"prog.py\"\n",[164,2332,2333,2336],{"class":166,"line":909},[164,2334,2335],{"class":188},"    script.write_text(textwrap.dedent(",[164,2337,2338],{"class":502},"\"\"\"\n",[164,2340,2341],{"class":166,"line":924},[164,2342,2343],{"class":502},"        import asyncio, sys\n",[164,2345,2346],{"class":166,"line":929},[164,2347,2348],{"class":502},"        async def main():\n",[164,2350,2351],{"class":166,"line":944},[164,2352,2353],{"class":502},"            try:\n",[164,2355,2356],{"class":166,"line":958},[164,2357,2358],{"class":502},"                await asyncio.sleep(30)\n",[164,2360,2362],{"class":166,"line":2361},58,[164,2363,2364],{"class":502},"            finally:\n",[164,2366,2368],{"class":166,"line":2367},59,[164,2369,2370],{"class":502},"                print(\"cleaned up\", flush=True)\n",[164,2372,2374],{"class":166,"line":2373},60,[164,2375,2376],{"class":502},"        try:\n",[164,2378,2380],{"class":166,"line":2379},61,[164,2381,2382],{"class":502},"            asyncio.run(main())\n",[164,2384,2386],{"class":166,"line":2385},62,[164,2387,2388],{"class":502},"        except KeyboardInterrupt:\n",[164,2390,2392],{"class":166,"line":2391},63,[164,2393,2394],{"class":502},"            sys.exit(130)\n",[164,2396,2398,2401],{"class":166,"line":2397},64,[164,2399,2400],{"class":502},"    \"\"\"",[164,2402,2403],{"class":188},"))\n",[164,2405,2407,2410,2412,2415,2417,2420,2423,2425,2428,2431,2433,2436,2438,2440],{"class":166,"line":2406},65,[164,2408,2409],{"class":188},"    proc ",[164,2411,305],{"class":177},[164,2413,2414],{"class":188}," subprocess.Popen([sys.executable, ",[164,2416,299],{"class":181},[164,2418,2419],{"class":188},"(script)], ",[164,2421,2422],{"class":311},"stdout",[164,2424,305],{"class":177},[164,2426,2427],{"class":188},"subprocess.",[164,2429,2430],{"class":181},"PIPE",[164,2432,353],{"class":188},[164,2434,2435],{"class":311},"text",[164,2437,305],{"class":177},[164,2439,705],{"class":181},[164,2441,320],{"class":188},[164,2443,2445,2448,2451],{"class":166,"line":2444},66,[164,2446,2447],{"class":188},"    time.sleep(",[164,2449,2450],{"class":181},"0.5",[164,2452,320],{"class":188},[164,2454,2456,2459,2461],{"class":166,"line":2455},67,[164,2457,2458],{"class":188},"    proc.send_signal(signal.",[164,2460,79],{"class":181},[164,2462,320],{"class":188},[164,2464,2466,2469,2471,2474,2476,2478,2481],{"class":166,"line":2465},68,[164,2467,2468],{"class":188},"    out, _ ",[164,2470,305],{"class":177},[164,2472,2473],{"class":188}," proc.communicate(",[164,2475,797],{"class":311},[164,2477,305],{"class":177},[164,2479,2480],{"class":181},"5",[164,2482,320],{"class":188},[164,2484,2486,2488,2491,2493],{"class":166,"line":2485},69,[164,2487,2170],{"class":177},[164,2489,2490],{"class":188}," proc.returncode ",[164,2492,2176],{"class":177},[164,2494,2495],{"class":181}," 130\n",[164,2497,2499,2501,2504,2507],{"class":166,"line":2498},70,[164,2500,2170],{"class":177},[164,2502,2503],{"class":502}," \"cleaned up\"",[164,2505,2506],{"class":177}," in",[164,2508,2509],{"class":188}," out\n",[10,2511,2512,2513,2515,2516,2518,2519,2521],{},"The first test proves the state object and file cleanup are right under cancellation; the second proves that ",[14,2514,50],{}," really turns ",[14,2517,79],{}," into cancellation that runs ",[14,2520,119],{}," blocks, which guards against a future refactor that installs its own signal handling incorrectly.",[37,2523,2525],{"id":2524},"conclusion","Conclusion",[10,2527,2528,2529,2531,2532,2534,2535,2537,2538,2540,2541,2543],{},"In modern asyncio, Ctrl+C is cancellation: ",[14,2530,50],{}," cancels the main task, ",[14,2533,54],{}," fans the cancellation out to every child, and each task unwinds through its ",[14,2536,119],{}," blocks. Your job is to not get in the way — never swallow ",[14,2539,20],{},", clean up in ",[14,2542,119],{},", shield only brief critical steps, time-box cleanup that touches the network — and then to tell the user exactly what state the work was left in before exiting with 130.",[37,2545,2547],{"id":2546},"frequently-asked-questions","Frequently asked questions",[1501,2549,2551],{"id":2550},"why-do-i-see-task-was-destroyed-but-it-is-pending","Why do I see \"Task was destroyed but it is pending\"?",[10,2553,2554,2555,2558,2559,2561],{},"A task was created with ",[14,2556,2557],{},"create_task"," and never awaited, and the loop closed while it was still running. Structured concurrency with ",[14,2560,54],{}," prevents it, because the group always waits for its children. If you must create background tasks, keep references and cancel and await them on shutdown.",[1501,2563,2565,2566,2568],{"id":2564},"can-i-catch-cancellederror-to-retry","Can I catch ",[14,2567,20],{}," to retry?",[10,2570,2571,2572,2575,2576,2578,2579,2581],{},"Only in the rare case where you are certain the cancellation came from a timeout you own. ",[14,2573,2574],{},"asyncio.timeout()"," already converts its own cancellation into ",[14,2577,1659],{},", so catch that instead and leave ",[14,2580,20],{}," alone.",[1501,2583,2585,2586,2589],{"id":2584},"what-happens-to-threads-started-with-asyncioto_thread","What happens to threads started with ",[14,2587,2588],{},"asyncio.to_thread","?",[10,2591,2592,2593,2597],{},"Cancelling the awaiting task stops ",[2594,2595,2596],"em",{},"waiting"," for the thread, but the thread keeps running until its function returns — threads cannot be interrupted. Keep work handed to threads short, or pass it a cancellation flag it checks.",[1501,2599,2601],{"id":2600},"does-this-work-on-windows","Does this work on Windows?",[10,2603,2604,2606,2607,2609,2610,2613,2614,2616],{},[14,2605,50],{},"'s ",[14,2608,79],{}," handling works on Windows. ",[14,2611,2612],{},"loop.add_signal_handler"," for ",[14,2615,1724],{}," is POSIX-only; on Windows, termination requests from other processes arrive differently and are usually abrupt.",[37,2618,2620],{"id":2619},"related","Related",[42,2622,2623,2629,2634,2639,2644],{},[45,2624,2625,2626],{},"Up: ",[31,2627,2628],{"href":33},"Concurrency and async in Python CLIs",[45,2630,2631],{},[31,2632,2633],{"href":61},"Running async code in Typer and Click",[45,2635,2636],{},[31,2637,2638],{"href":68},"Handling KeyboardInterrupt cleanly",[45,2640,2641],{},[31,2642,2643],{"href":1741},"Handling SIGTERM and graceful shutdown",[45,2645,2646],{},[31,2647,2649],{"href":2648},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python\u002F","Downloading files with progress in Python",[2651,2652,2653],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":160,"searchDepth":174,"depth":174,"links":2655},[2656,2657,2658,2662,2663,2664,2665,2673],{"id":39,"depth":174,"text":40},{"id":72,"depth":174,"text":73},{"id":145,"depth":174,"text":146,"children":2659},[2660,2661],{"id":1503,"depth":192,"text":1504},{"id":1575,"depth":192,"text":1576},{"id":1676,"depth":174,"text":1677},{"id":1745,"depth":174,"text":1746},{"id":2524,"depth":174,"text":2525},{"id":2546,"depth":174,"text":2547,"children":2666},[2667,2668,2670,2672],{"id":2550,"depth":192,"text":2551},{"id":2564,"depth":192,"text":2669},"Can I catch CancelledError to retry?",{"id":2584,"depth":192,"text":2671},"What happens to threads started with asyncio.to_thread?",{"id":2600,"depth":192,"text":2601},{"id":2619,"depth":174,"text":2620},"2026-09-18","Make Ctrl+C stop an asyncio CLI cleanly: how asyncio.run cancels tasks, cleanup in finally, shielding critical writes, bounded shutdown and exit code 130.","advanced",false,"md",{},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fcancelling-async-tasks-on-ctrl-c",{"title":5,"description":2675},"cli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fcancelling-async-tasks-on-ctrl-c\u002Findex",[28,2684,2685,2686],"cancellation","signals","keyboardinterrupt","hHQ9XDLdzYZ2AoOuuZdn7jX0h1oqKgPm_J_S5HgURqY",[2689,2692,2695,2698,2701,2704,2707,2710,2713,2716,2719,2722,2725,2728,2731,2734,2737,2740,2743,2746,2749,2752,2755,2758,2761,2764,2767,2770,2773,2776,2779,2782,2785,2788,2791,2794,2797,2800,2803,2806,2809,2812,2815,2818,2821,2824,2827,2830,2833,2836,2839,2842,2845,2848,2851,2854,2857,2860,2863,2866,2869,2872,2873,2876,2879,2882,2885,2888,2891,2894,2897,2900,2903,2906,2909,2912,2915,2918,2921,2924,2927,2930,2933,2936,2939,2942,2945,2948,2951,2954,2957,2960,2962,2965,2968,2971,2974,2977,2980,2983,2986,2989,2992,2995,2998,3001,3004,3007,3010,3013,3016,3019,3022,3025,3028,3031,3034,3037,3040,3043,3046,3049,3052,3055,3058,3061,3064,3067,3070,3073,3076,3079,3082,3085,3088,3091,3094,3097,3100,3103,3106,3109,3112,3115,3118,3121,3124,3127,3130,3133,3136,3139,3142,3145,3148,3151,3154,3157,3160,3163,3166,3169,3172,3175,3178,3181,3184,3187,3190,3193,3196,3199,3202,3205,3208,3211,3214,3217,3220,3223,3226,3229,3232],{"path":2690,"title":2691},"\u002Fabout","About Python CLI Toolcraft",{"path":2693,"title":2694},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":2696,"title":2697},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":2699,"title":2700},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":2702,"title":2703},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":2705,"title":2706},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":2708,"title":2709},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fbuilding-your-first-textual-app","Building Your First Textual App for a Python CLI",{"path":2711,"title":2712},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fchoosing-between-a-cli-a-prompt-flow-and-a-tui","Choosing Between a CLI, a Prompt Flow and a TUI",{"path":2714,"title":2715},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":2717,"title":2718},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":2720,"title":2721},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fadding-examples-and-epilogs-to-help-output","Adding Examples and Epilogs to Help Output",{"path":2723,"title":2724},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fgenerating-man-pages-and-docs-from-a-cli","Generating Man Pages and Docs from a CLI",{"path":2726,"title":2727},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":2729,"title":2730},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":2732,"title":2733},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":2735,"title":2736},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":2738,"title":2739},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":2741,"title":2742},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Ffixing-unicode-and-encoding-errors-on-windows","Fixing Unicode and Encoding Errors on Windows in Python CLIs",{"path":2744,"title":2745},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":2747,"title":2748},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Frespecting-no-color-and-force-color","Respecting NO_COLOR and FORCE_COLOR in Python CLIs",{"path":2750,"title":2751},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":2753,"title":2754},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fdesigning-an-exception-hierarchy-for-a-cli","Designing an Exception Hierarchy for a Python CLI",{"path":2756,"title":2757},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":2759,"title":2760},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":2762,"title":2763},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":2765,"title":2766},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Freporting-machine-readable-errors-in-json-mode","Reporting Machine-Readable Errors in JSON Mode",{"path":2768,"title":2769},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":2771,"title":2772},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fdiscovering-project-config-files-by-walking-up-directories","Discovering Project Config Files by Walking Up Directories",{"path":2774,"title":2775},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":2777,"title":2778},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Floading-yaml-configs-safely-in-cli-apps","Loading YAML configs safely in CLI apps",{"path":2780,"title":2781},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":2783,"title":2784},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":2786,"title":2787},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":2789,"title":2790},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fadding-progress-bars-and-spinners-to-python-clis","Progress Bars and Spinners for Python CLIs",{"path":2792,"title":2793},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":2795,"title":2796},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":2798,"title":2799},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":2801,"title":2802},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":2804,"title":2805},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":2807,"title":2808},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fdynamic-completion-values-from-apis-and-files","Dynamic Completion Values from APIs and Files",{"path":2810,"title":2811},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fenabling-tab-completion-in-click-and-typer","Enabling Tab Completion in Click and Typer",{"path":2813,"title":2814},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":2816,"title":2817},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Finstalling-shell-completion-for-bash-zsh-fish","Installing Shell Completion for bash, zsh, fish",{"path":2819,"title":2820},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":2822,"title":2823},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs","Adding Trace IDs and Context to Python CLI Logs",{"path":2825,"title":2826},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":2828,"title":2829},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":2831,"title":2832},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2834,"title":2835},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fwriting-rotating-log-files-from-a-cli","Writing Rotating Log Files from a Python CLI",{"path":2837,"title":2838},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2840,"title":2841},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2843,"title":2844},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2846,"title":2847},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2849,"title":2850},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fprocessing-large-files-and-ndjson-streams","Processing Large Files and NDJSON Streams in Python CLIs",{"path":2852,"title":2853},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2855,"title":2856},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fbuilding-an-api-client-cli-with-httpx","Building an API Client CLI with httpx",{"path":2858,"title":2859},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":2861,"title":2862},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis","Calling HTTP APIs from Python CLIs",{"path":2864,"title":2865},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2867,"title":2868},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2870,"title":2871},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fretries-and-backoff-for-cli-http-calls","Retries and Backoff for CLI HTTP Calls",{"path":2680,"title":5},{"path":2874,"title":2875},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2877,"title":2878},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2880,"title":2881},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2883,"title":2884},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2886,"title":2887},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frunning-async-code-in-typer-and-click","Running Async Code in Typer and Click",{"path":2889,"title":2890},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2892,"title":2893},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2895,"title":2896},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2898,"title":2899},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2901,"title":2902},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":2904,"title":2905},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2907,"title":2908},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2910,"title":2911},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fbuilding-a-watch-mode-with-watchfiles","Building a Watch Mode with watchfiles in Python",{"path":2913,"title":2914},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2916,"title":2917},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhealth-checks-and-heartbeats-for-long-running-clis","Health Checks and Heartbeats for Long-Running CLIs",{"path":2919,"title":2920},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2922,"title":2923},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Frunning-a-cli-on-a-schedule-with-cron-and-systemd","Running a Python CLI on a Schedule with cron and systemd",{"path":2925,"title":2926},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2928,"title":2929},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2931,"title":2932},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2934,"title":2935},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2937,"title":2938},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2940,"title":2941},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fwrapping-git-and-other-tools-from-a-python-cli","Wrapping git and Other Tools from a Python CLI",{"path":2943,"title":2944},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2946,"title":2947},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2949,"title":2950},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Freading-secrets-from-env-and-files","Reading Secrets from Env Vars and Files in CLIs",{"path":2952,"title":2953},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fredacting-secrets-from-cli-output-and-logs","Redacting Secrets from CLI Output and Logs",{"path":2955,"title":2956},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2958,"title":2959},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":918,"title":2961},"Python CLI Toolcraft",{"path":2963,"title":2964},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs","Caching Expensive Work Between Python CLI Runs",{"path":2966,"title":2967},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2969,"title":2970},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2972,"title":2973},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2975,"title":2976},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2978,"title":2979},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2981,"title":2982},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2984,"title":2985},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2987,"title":2988},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2990,"title":2991},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2993,"title":2994},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2996,"title":2997},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fadding-dry-run-and-confirmation-to-destructive-commands","Adding Dry-Run and Confirmation to Destructive Commands",{"path":2999,"title":3000},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Ffollowing-posix-and-gnu-argument-conventions","Following POSIX and GNU Argument Conventions in Python",{"path":3002,"title":3003},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fglobal-options-vs-per-command-options","Global Options vs Per-Command Options in Python CLIs",{"path":3005,"title":3006},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":3008,"title":3009},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":3011,"title":3012},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":3014,"title":3015},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":3017,"title":3018},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":3020,"title":3021},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":3023,"title":3024},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":3026,"title":3027},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fwriting-a-plugin-for-an-existing-cli","Writing a Plugin for an Existing CLI",{"path":3029,"title":3030},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fbest-practices-for-python-cli-entry-points","Best practices for Python CLI entry points",{"path":3032,"title":3033},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":3035,"title":3036},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fhow-to-structure-a-large-python-cli-project","Structuring a Large Python CLI Project",{"path":3038,"title":3039},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":3041,"title":3042},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":3044,"title":3045},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":3047,"title":3048},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fend-to-end-testing-an-installed-cli","End-to-End Testing an Installed Python CLI",{"path":3050,"title":3051},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":3053,"title":3054},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":3056,"title":3057},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmocking-filesystem-and-network-in-cli-tests","Mocking the Filesystem and Network in CLI Tests",{"path":3059,"title":3060},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":3062,"title":3063},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":3065,"title":3066},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":3068,"title":3069},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":3071,"title":3072},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-a-cli-with-subcommands-in-click","Building a CLI with subcommands in Click",{"path":3074,"title":3075},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":3077,"title":3078},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fconverting-a-click-app-to-typer","Converting a Click App to Typer",{"path":3080,"title":3081},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":3083,"title":3084},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":3086,"title":3087},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":3089,"title":3090},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":3092,"title":3093},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":3095,"title":3096},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":3098,"title":3099},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fpublishing-to-pypi-with-trusted-publishing","Publishing a CLI to PyPI with Trusted Publishing",{"path":3101,"title":3102},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fsmoke-testing-the-built-wheel-in-ci","Smoke-Testing the Built Wheel of a Python CLI in CI",{"path":3104,"title":3105},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Ftesting-a-cli-across-python-versions-with-github-actions","Testing a CLI Across Python Versions in GitHub Actions",{"path":3107,"title":3108},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":3110,"title":3111},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":3113,"title":3114},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":3116,"title":3117},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":3119,"title":3120},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":3122,"title":3123},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":3125,"title":3126},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":3128,"title":3129},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":3131,"title":3132},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":3134,"title":3135},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fshipping-a-cli-as-a-zipapp-with-shiv","Shipping a CLI as a Zipapp with shiv",{"path":3137,"title":3138},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":3140,"title":3141},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":3143,"title":3144},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fenforcing-import-boundaries-in-a-cli-codebase","Enforcing Import Boundaries in a Python CLI Codebase",{"path":3146,"title":3147},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":3149,"title":3150},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Ftype-checking-click-and-typer-code-with-mypy","Type-Checking Click and Typer Code with mypy",{"path":3152,"title":3153},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":3155,"title":3156},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fderiving-versions-from-git-tags-with-hatch-vcs","Deriving CLI Versions from Git Tags with hatch-vcs",{"path":3158,"title":3159},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":3161,"title":3162},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":3164,"title":3165},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":3167,"title":3168},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":3170,"title":3171},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":3173,"title":3174},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":3176,"title":3177},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":3179,"title":3180},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":3182,"title":3183},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fwriting-pyproject-toml-metadata-for-a-cli","Writing pyproject.toml Metadata for a Python CLI",{"path":3185,"title":3186},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":3188,"title":3189},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fmigrating-a-cli-from-poetry-to-uv","Migrating a Python CLI from Poetry to uv",{"path":3191,"title":3192},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":3194,"title":3195},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":3197,"title":3198},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":3200,"title":3201},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fsetting-up-pre-commit-for-python-cli-repos","Setting up pre-commit for Python CLI repos",{"path":3203,"title":3204},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fshipping-your-cli-as-a-pre-commit-hook","Shipping Your Python CLI as a pre-commit Hook",{"path":3206,"title":3207},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fwriting-local-pre-commit-hooks-in-python","Writing Local pre-commit Hooks in Python",{"path":3209,"title":3210},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":3212,"title":3213},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Frunning-one-off-cli-scripts-with-uv-run","Running One-Off CLI Scripts with uv run and PEP 723",{"path":3215,"title":3216},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-init-vs-poetry-init-for-cli-tools","uv init vs poetry init for CLI tools",{"path":3218,"title":3219},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-tool-install-vs-pipx-for-clis","uv tool install vs pipx for CLIs",{"path":3221,"title":3222},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":3224,"title":3225},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":3227,"title":3228},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":3230,"title":3231},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":3233,"title":3234},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905048]