Skip to content

test: add xfail test for gevent + asyncio event loop in greenlet bug - #263

Draft
freider wants to merge 2 commits into
mainfrom
stilla/add-gevent-asyncio-greenlet-test
Draft

test: add xfail test for gevent + asyncio event loop in greenlet bug#263
freider wants to merge 2 commits into
mainfrom
stilla/add-gevent-asyncio-greenlet-test

Conversation

@freider

@freider freider commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new xfail test that captures a known bug: when gevent (monkey.patch_all()) is active and an asyncio event loop is running inside one greenlet, calling synchronicity blocking functions from another greenlet fails with:

RuntimeError: asyncio.run() cannot be called from a running event loop

Root Cause

Under gevent, asyncio._get_running_loop() is patched to be visible globally (not just to the thread running the loop). So when any greenlet calls asyncio.run() internally (as synchronicity does), it sees the event loop running in another greenlet and raises RuntimeError.

Changes

  • test/support/_gevent_asyncio_in_greenlet.py: New script that reproduces the bug — spawns a greenlet with a running asyncio loop and calls a synchronicity blocking function from another greenlet simultaneously.
  • test/gevent_test.py: New test test_gevent_asyncio_in_greenlet marked @pytest.mark.xfail(strict=True) with the same skip conditions as test_gevent.

Status

Intentionally xfail — documents the bug. Fix to follow in a separate PR.

Sent by @freider from gevent/asyncio RuntimeError investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant