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

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

## Root Cause

A synchronization primitive (Semaphore, Lock, Event) created in one event loop is used in another, typically when a module-level primitive is reused across asyncio.run() calls or threads.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   async def main():
    sem = asyncio.Semaphore(10)  # created inside running loop
    await asyncio.gather(*(worker(sem) for _ in range(100)))

asyncio.run(main())
   ```
2. **** (85% success)
   ```
   loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
sem = asyncio.Semaphore(10)  # created once
loop.run_until_complete(main(sem))
# subsequent runs reuse the same loop
   ```

## Dead Ends

- **** — Touching private attributes breaks invariants and usually still fails on the next acquire. (90% fail)
- **** — The primitive is unusable in the new loop; the exception recurs on every call. (85% fail)
