# RuntimeError: There is no current event loop in thread 'MainThread'.

- **ID:** `python/asyncio-event-loop-is-running-pytest`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Since Python 3.10, asyncio.get_event_loop() no longer creates a loop implicitly when called from a thread with no running loop; code that relied on the old behavior raises this error, common in pytest and background threads.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
    loop.run_until_complete(main())
finally:
    loop.close()
   ```
2. **** (92% success)
   ```
   # pytest.ini: asyncio_mode = auto
import pytest
@pytest.mark.asyncio
async def test_foo():
    assert await foo() == 1
   ```

## Dead Ends

- **** — Blocks upgrades and the behavior is slated for removal; not a durable fix. (70% fail)
- **** — Makes get_event_loop raise immediately; does not provide a usable loop. (85% fail)
