Mastering-Concurrency-in-Python icon indicating copy to clipboard operation
Mastering-Concurrency-in-Python copied to clipboard

Remove deprecated parameter 'loop' in Python 3.10 and newer

Open Matej-Chmel opened this issue 2 years ago • 0 comments
trafficstars

When running the echo server example from chapter 10 under Python 3.10 or newer a TypeError is raised:

TypeError: BaseEventLoop.create_server() got an unexpected keyword argument 'loop'

The solution is to simply remove the 'loop' argument from line 17.

coro = asyncio.start_server(handle_echo, '127.0.0.1', 8888, loop=loop) # original
coro = asyncio.start_server(handle_echo, '127.0.0.1', 8888) # solution

This can be done safely because the function asyncio.get_event_loop that is used internally by asyncio.start_server always returns the currently running loop from Python 3.6 onwards.

Matej-Chmel avatar Sep 02 '23 22:09 Matej-Chmel