{
  "id": "python/asyncio-loop-created-in-thread",
  "signature": "RuntimeError: There is no current event loop in thread 'Thread-1'",
  "signature_zh": "运行时错误：线程'Thread-1'中没有当前事件循环",
  "regex": "RuntimeError:\\ There\\ is\\ no\\ current\\ event\\ loop\\ in\\ thread\\ 'Thread\\-1'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to use asyncio functions in a thread without a running event loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "在没有运行事件循环的线程中尝试使用asyncio函数。",
  "versions": [
    {
      "version": "3.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "In Python 3.10+, it may raise an error or return a closed loop.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "asyncio.run() creates a new loop, but it's not accessible from other threads.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop); loop.run_until_complete(coro())",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "future = asyncio.run_coroutine_threadsafe(coro(), loop)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}