Skip to content

Commit 81ba8aa

Browse files
[PR #7316/6f3e7f46 backport][3.8] Update docs (#7317)
**This is a backport of PR #7316 as merged into master (6f3e7f4).** Call main() does not returns any loop. Close #7314 Co-authored-by: Serhii A <[email protected]>
1 parent e71432e commit 81ba8aa

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

docs/client_reference.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Usage example::
3232
html = await fetch(client)
3333
print(html)
3434

35-
loop = asyncio.get_event_loop()
36-
loop.run_until_complete(main())
35+
asyncio.run(main())
3736

3837

3938
The client session supports the context manager protocol for self closing.

docs/http_request_lifecycle.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ So you are expected to reuse a session object and make many requests from it. Fo
7777
html = await response.text()
7878
print(html)
7979
80-
loop = asyncio.get_event_loop()
81-
loop.run_until_complete(main())
80+
asyncio.run(main())
8281
8382
8483
Can become this:
@@ -98,8 +97,7 @@ Can become this:
9897
html = await fetch(session, 'http://python.org')
9998
print(html)
10099
101-
loop = asyncio.get_event_loop()
102-
loop.run_until_complete(main())
100+
asyncio.run(main())
103101
104102
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.
105103

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ Client example
8383
html = await response.text()
8484
print("Body:", html[:15], "...")
8585
86-
loop = asyncio.get_event_loop()
87-
loop.run_until_complete(main())
86+
asyncio.run(main())
8887
8988
This prints:
9089

docs/web_lowlevel.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ The following code demonstrates very trivial usage example::
6969
await asyncio.sleep(100*3600)
7070

7171

72-
loop = asyncio.get_event_loop()
73-
74-
try:
75-
loop.run_until_complete(main())
76-
except KeyboardInterrupt:
77-
pass
78-
loop.close()
72+
asyncio.run(main())
7973

8074

8175
In the snippet we have ``handler`` which returns a regular

0 commit comments

Comments
 (0)