thriftpy2
thriftpy2 copied to clipboard
RuntimeError on Python 3.14 with asyncio
I run examples/asyncio_echo/server.py on Python 3.14,
and I got this error:
$ cd examples/asyncio_echo/
$ python server.py
Traceback (most recent call last):
File "~/thriftpy2/examples/asyncio_echo/server.py", line 24, in <module>
main()
~~~~^^
File "~/thriftpy2/examples/asyncio_echo/server.py", line 20, in main
server.serve()
~~~~~~~~~~~~^^
File "/usr/lib/python3.14/site-packages/thriftpy2/contrib/aio/server.py", line 18, in serve
self.init_server()
~~~~~~~~~~~~~~~~^^
File "/usr/lib/python3.14/site-packages/thriftpy2/contrib/aio/server.py", line 27, in init_server
self.loop = asyncio.get_event_loop()
~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/elephant/workspace/opensource/python/pyenv/versions/3.14.0/lib/python3.14/asyncio/events.py", line 715, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'MainThread'.
environment:
OS: Ubuntu 20.04.6 LTS
Python:
Python 3.14.0 (main, Oct 13 2025, 11:23:29) [GCC 9.4.0] on linux
pip:
$ pip freeze
ply==3.11
six==1.17.0
thriftpy2==0.5.3
Python 3.14 includes some breaking changes about asyncio: asyncio.get_event_loop() now raises a RuntimeError if there is no current event loop, and no longer implicitly creates an event loop.
https://github.com/Thriftpy/thriftpy2/blob/88923d61fa995e615d51a67d333c7686cda2a764/thriftpy2/contrib/aio/server.py#L26-L27 should be
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self.loop = asyncio.get_event_loop()