# RuntimeError: <asyncio.locks.Semaphore object at 0x...> is bound to a different event loop

- **ID:** `python/asyncio-semaphore-bound-in-different-loop`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An asyncio synchronization primitive (Semaphore, Lock, Event, Queue) was created under one loop and used under another, common when module-level primitives are reused across asyncio.run() calls.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8+ | active | — | — |
| 3.9+ | active | — | — |
| 3.10+ | active | — | — |
| 3.11+ | active | — | — |
| 3.12+ | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   async def main():
    sem = asyncio.Semaphore(10)  # created inside the loop
    await run_all(sem)

asyncio.run(main())
   ```
2. **** (90% success)
   ```
   loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())  # reuse loop; do not call asyncio.run() repeatedly
   ```

## Dead Ends

- **** — Private attribute hack; the semaphore's internal waiters still reference the old loop. (85% fail)
- **** — The primitive is still bound to its original loop; new loop does not fix it. (80% fail)
