fix(docs): IO Concurrency for 3.10+#677
Merged
dbrattli merged 1 commit intoReactiveX:masterfrom Dec 30, 2022
Merged
Conversation
The current example returns errors when run on Python 3.10+. The new example should work on Python 3.7+. 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. [Python 3.10 Removed](https://docs.python.org/3/whatsnew/3.10.html#removed) [Python 3.10 Changes in the Python API](https://docs.python.org/3/whatsnew/3.10.html#changes-in-the-python-api) The result of `asyncio.get_event_loop()` appears to be system dependent. The [documentation](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop) 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()](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop) function is preferred to [get_event_loop()](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.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. ``` 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' ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_serverlost its loop parameter in Python 3.10 as part of a cleanup of the high-level asyncio api. The functionasyncio.create_serverhas 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 readsIf 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