Repository navigation
Description
What version of gRPC and what language are you using?
1.71.0
Python
What operating system (Linux, Windows,...) and version?
Linux (ubuntu, rodete)
What runtime / compiler are you using (e.g. python version or version of gcc)
Python 3.14.0b1
gcc version 14.2.0 (Debian 14.2.0-19+build4)
What did you do?
Please provide either 1) A unit test for reproducing the bug or 2) Specific steps for us to follow to reproduce the bug. If there’s not enough information to debug the problem, gRPC team may close the issue at their discretion. You’re welcome to re-open the issue once you have a reproduction.
Install Python 3.14.0b1 from https://www.python.org/downloads/release/python-3140b1/
Observe the error below
partheniou@partheniou-vm-3:~/Python-3.14.0b1$ python3.14
Python 3.14.0b1 (main, May 7 2025, 19:23:10) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import grpc
>>> from grpc import aio
>>> print(grpc.__version__)
1.71.0
>>> aio.secure_channel("http://localhost/", grpc.local_channel_credentials())
Traceback (most recent call last):
File "src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi", line 184, in grpc._cython.cygrpc.get_working_loop
RuntimeError: no running event loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi", line 190, in grpc._cython.cygrpc.get_working_loop
File "/usr/local/lib/python3.14/asyncio/events.py", line 805, in get_event_loop_policy
warnings._deprecated('asyncio.get_event_loop_policy', remove=(3, 16))
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/_py_warnings.py", line 830, in _deprecated
_wm.warn(msg, DeprecationWarning, stacklevel=3)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DeprecationWarning: 'asyncio.get_event_loop_policy' is deprecated and slated for removal in Python 3.16
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
aio.secure_channel("http://localhost/", grpc.local_channel_credentials())
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/partheniou/.local/lib/python3.14/site-packages/grpc/aio/_channel.py", line 621, in secure_channel
return Channel(
target,
...<3 lines>...
interceptors,
)
File "/usr/local/google/home/partheniou/.local/lib/python3.14/site-packages/grpc/aio/_channel.py", line 367, in __init__
self._loop = cygrpc.get_working_loop()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi", line 186, in grpc._cython.cygrpc.get_working_loop
File "src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi", line 194, in grpc._cython.cygrpc.get_working_loop
File "/usr/local/lib/python3.14/asyncio/events.py", line 805, in get_event_loop_policy
warnings._deprecated('asyncio.get_event_loop_policy', remove=(3, 16))
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/_py_warnings.py", line 830, in _deprecated
_wm.warn(msg, DeprecationWarning, stacklevel=3)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DeprecationWarning: 'asyncio.get_event_loop_policy' is deprecated and slated for removal in Python 3.16
>>>
What did you expect to see?
I expected aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) to succeed
What did you see instead?
I saw
>>> aio.secure_channel("http://localhost/", grpc.local_channel_credentials())
Traceback (most recent call last):
File "src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi", line 184, in grpc._cython.cygrpc.get_working_loop
RuntimeError: no running event loop
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
See TROUBLESHOOTING.md for how to diagnose problems better.
Activity
[-]bug(Python): `RuntimeError: no running event loop` when using Python 3.14.0a7[/-][+]bug(Python): `RuntimeError: no running event loop` when using Python 3.14.0b1[/+]parthea commentedon May 8, 2025
Some differences between 3.13 and 3.14
asyncio.get_event_loop_policy().get_event_loop()now raisesRuntimeError: There is no current event loop in thread 'MainThread'because there is no event loopasyncio.get_event_loop_policy()emits deprecation warningDeprecationWarning: 'asyncio.get_event_loop_policy' is deprecated and slated for removal in Python 3.16The code below could be changed to swallow the
DeprecationWarning: There is no current event loopwhich appears in Python 3.12/3.13 without treating all deprecation warnings as errors. We also need to handle the newRuntimeErrorwhen there is no event loop when callingasyncio.get_event_loop_policy().get_event_loop()grpc/src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi
Lines 186 to 194 in 1168209
Testing:
We would still need to migrate off
asyncio.get_event_loop_policy()prior to Python 3.16 as stated by the deprecation warning. I'll file a separate issue for that.parthea commentedon May 8, 2025
With both #39523 and #39525, testing looks good for
Python 3.14.0b1sergiitk commentedon Jul 22, 2025
I don't think to suppressing
RuntimeErrorwhen no aio loop is running (as proposed in #39523) is the right thing to do.Note that in the reproduction case
aio.secure_channel("http://localhost/", grpc.local_channel_credentials())is executed outside of anasyncfunction, which would normally be executed by a runner handling the event loop creation.To work with awaitable objects in REPL, Python provides asyncio REPL.
An example without asyncio REPL:
An example with asyncio REPL:
Same examples using Python 3.11:
That said, the gRPC Python team will consider what's the right way to handle the
RuntimeError: no running event loop. I think we at least should start displaying a deprecation warning when gRPC aio methods are executed outside of the event loop context.sergiitk commentedon Jul 23, 2025
Found some historical context for the current behavior (create loops on demand instead of RuntimeError): #23377.
We may have to preserve this approach after all. Will investigate further.
[Python][Support 3.14] Enable 3.14 in Python Basic, Bazel and Distrib…
[Python][Support 3.14] Enable 3.14 in Python Basic, Bazel and Distrib…
[Python][Support 3.14] Enable 3.14 in Python Basic, Bazel and Distrib…
[Backport][v1.75.x][Python][Support 3.14] Enable 3.14 supported wheels (
[Python] Handle python3.14 get_event_loop behavior changes (grpc#40750)
[Python] Handle python3.14 get_event_loop behavior changes (grpc#40750)
[Backport][v1.75.x][Python] Handle python3.14 get_event_loop behavior…
[-]bug(Python): `RuntimeError: no running event loop` when using Python 3.14.0b1[/-][+][Python] `RuntimeError: no running event loop` when using Python 3.14.0b1[/+]sergiitk commentedon Sep 23, 2025
Fixed by #40750.
[Python] Handle python3.14 get_event_loop behavior changes (grpc#40750)