From 6f3e7f4687089ecb085a49aadbe372e5408fb9bb Mon Sep 17 00:00:00 2001 From: Serhii A Date: Fri, 9 Jun 2023 21:30:52 +0300 Subject: [PATCH] Update docs (#7316) Call main() does not returns any loop. Close #7314 --- docs/client_reference.rst | 3 +-- docs/http_request_lifecycle.rst | 6 ++---- docs/index.rst | 3 +-- docs/web_lowlevel.rst | 8 +------- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/docs/client_reference.rst b/docs/client_reference.rst index c33f2ca7bee..ee7f7503572 100644 --- a/docs/client_reference.rst +++ b/docs/client_reference.rst @@ -32,8 +32,7 @@ Usage example:: html = await fetch(client) print(html) - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) + asyncio.run(main()) The client session supports the context manager protocol for self closing. diff --git a/docs/http_request_lifecycle.rst b/docs/http_request_lifecycle.rst index e14fb03de5f..22f6fbb8e30 100644 --- a/docs/http_request_lifecycle.rst +++ b/docs/http_request_lifecycle.rst @@ -77,8 +77,7 @@ So you are expected to reuse a session object and make many requests from it. Fo html = await response.text() print(html) - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) + asyncio.run(main()) Can become this: @@ -98,8 +97,7 @@ Can become this: html = await fetch(session, 'http://python.org') print(html) - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) + asyncio.run(main()) On more complex code bases, you can even create a central registry to hold the session object from anywhere in the code, or a higher level ``Client`` class that holds a reference to it. diff --git a/docs/index.rst b/docs/index.rst index 161f3be01b5..de31c33d620 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -83,8 +83,7 @@ Client example html = await response.text() print("Body:", html[:15], "...") - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) + asyncio.run(main()) This prints: diff --git a/docs/web_lowlevel.rst b/docs/web_lowlevel.rst index 456b8fea4cd..6d76ca3b95c 100644 --- a/docs/web_lowlevel.rst +++ b/docs/web_lowlevel.rst @@ -69,13 +69,7 @@ The following code demonstrates very trivial usage example:: await asyncio.sleep(100*3600) - loop = asyncio.get_event_loop() - - try: - loop.run_until_complete(main()) - except KeyboardInterrupt: - pass - loop.close() + asyncio.run(main()) In the snippet we have ``handler`` which returns a regular