{"record":{"id":"3a87f4aa00b96344","repo":"fxsjy/jieba","slug":"jieba-parallel-mode-only-supports-posix-system","errorCode":null,"errorMessage":"jieba: parallel mode only supports posix system","messagePattern":"jieba: parallel mode only supports posix system","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"warning","filePath":"jieba/__init__.py","lineNumber":601,"sourceCode":"    else:\n        result = pool.map(_lcut_for_search_no_hmm, parts)\n    for r in result:\n        for w in r:\n            yield w\n\n\ndef enable_parallel(processnum=None):\n    \"\"\"\n    Change the module's `cut` and `cut_for_search` functions to the\n    parallel version.\n\n    Note that this only works using dt, custom Tokenizer\n    instances are not supported.\n    \"\"\"\n    global pool, dt, cut, cut_for_search\n    from multiprocessing import cpu_count\n    if os.name == 'nt':\n        raise NotImplementedError(\n            \"jieba: parallel mode only supports posix system\")\n    else:\n        from multiprocessing import Pool\n    dt.check_initialized()\n    if processnum is None:\n        processnum = cpu_count()\n    pool = Pool(processnum)\n    cut = _pcut\n    cut_for_search = _pcut_for_search\n\n\ndef disable_parallel():\n    global pool, dt, cut, cut_for_search\n    if pool:\n        pool.close()\n        pool = None\n    cut = dt.cut\n    cut_for_search = dt.cut_for_search","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/fxsjy/jieba/blob/67fa2e36e72f69d9134b8a1037b83fbb070b9775/jieba/__init__.py#L583-L619","documentation":"jieba's parallel mode spawns a multiprocessing Pool of worker processes, which is only implemented for POSIX systems. On Windows (os.name == 'nt') enable_parallel raises NotImplementedError instead of silently degrading.","triggerScenarios":"Calling jieba.enable_parallel(n) on Windows (os.name == 'nt'). Any call, with or without an explicit process count, triggers it.","commonSituations":"Code developed on Linux/macOS and deployed to Windows; CI running on windows-latest; tutorials recommending enable_parallel being followed verbatim on Windows.","solutions":["Guard the call: only invoke enable_parallel when os.name != 'nt'","Keep sequential mode on Windows — it is correct, just slower","For cross-platform code, gate behind a platform check or sys.platform.startswith('linux')"],"exampleFix":"# before\nimport jieba\njieba.enable_parallel(4)  # crashes on Windows\n\n# after\nimport os, jieba\nif os.name != 'nt':\n    jieba.enable_parallel(4)","handlingStrategy":"validation","validationCode":"import os\nif os.name != 'nt':\n    jieba.enable_parallel(4)\n# else: stay sequential","typeGuard":null,"tryCatchPattern":"try:\n    jieba.enable_parallel(4)\nexcept NotImplementedError:\n    pass  # sequential fallback on Windows","preventionTips":["Treat parallelism as an optional optimization, guarded by platform checks","Test on Windows in CI if you deploy there","Call disable_parallel() in finally blocks to clean up pools"],"tags":["jieba","parallel","platform","windows"],"backgroundTag":"platform-not-supported","analyzedSha":"67fa2e36e72f69d9134b8a1037b83fbb070b9775","analyzedAt":"2026-08-27T11:28:25.101Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}