The current example returns errors when run on Python 3.10+.
The new example should work on Python 3.7+.
Details
Missing loop parameter
The function asyncio.create_server lost its loop parameter in Python 3.10 as part of a cleanup of the high-level asyncio api. The function asyncio.create_server has been implicitly retrieving the current loop since Python 3.7.
The result of asyncio.get_event_loop() appears to be system dependent. The documentation reads
_If there is no running event loop set, the function will return the result of get_event_loop_policy().get_event_loop() call._
_Because this function has rather complex behavior (especially when custom event loop policies are in use), using the get_running_loop() function is preferred to get_event_loop() in coroutines and callbacks._
Since the example did not start an event loop on my system, I took the liberty of writing asyncio.new_event_loop() instead.
Error encountered
Current code returns:
/tmp/io.py:47: DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
starting server
Task exception was never retrieved
future: <Task finished name='Task-1' coro=<start_server() done, defined at /usr/local/lib/python3.11/asyncio/streams.py:54> exception=TypeError("BaseEventLoop.create_server() got an unexpected keyword argument 'loop'")>
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/streams.py", line 85, in start_server
return await loop.create_server(factory, host, port, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseEventLoop.create_server() got an unexpected keyword argument 'loop'
Coverage: 93.375% (-0.0%) from 93.375% when pulling 2ddd0d8bfe1a0c7d4378a1486739cf9d1e6617d8 on salticus:master into a138cca5f0ef4fbda7dc4071c0e91459032dd3c1 on ReactiveX:master.
The current example returns errors when run on Python 3.10+.
The new example should work on Python 3.7+.
Details
Missing loop parameter
The function
asyncio.create_server
lost its loop parameter in Python 3.10 as part of a cleanup of the high-level asyncio api. The functionasyncio.create_server
has been implicitly retrieving the current loop since Python 3.7.Python 3.10 Removed
Python 3.10 Changes in the Python API
Missing event loop
The result of
asyncio.get_event_loop()
appears to be system dependent. The documentation reads_If there is no running event loop set, the function will return the result of
get_event_loop_policy().get_event_loop()
call.__Because this function has rather complex behavior (especially when custom event loop policies are in use), using the get_running_loop() function is preferred to get_event_loop() in coroutines and callbacks._
Since the example did not start an event loop on my system, I took the liberty of writing
asyncio.new_event_loop()
instead.Error encountered