Skip to content

Commit 97ebc1c

Browse files
author
rodrigo.nogueira
committed
docs: move dynamic port docs from advanced guide to TCPSite reference
Per maintainer feedback, the dynamic port binding explanation and example is more useful in the TCPSite reference docs where users looking up TCPSite will naturally find it, rather than buried in the advanced guide.
1 parent c0b0f83 commit 97ebc1c

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

docs/web_advanced.rst

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,27 +1279,6 @@ the middleware might use :meth:`BaseRequest.clone`.
12791279
for modifying *scheme*, *host* and *remote* attributes according
12801280
to ``Forwarded`` and ``X-Forwarded-*`` HTTP headers.
12811281

1282-
Deploying with a dynamic port
1283-
-----------------------------
1284-
1285-
When deploying aiohttp with zero-configuration networking, it may be useful
1286-
to have the server bind to a dynamic port. This can be done by
1287-
using the ``0`` port number. This will cause the OS to assign a
1288-
free port to the server. The assigned port can be retrieved
1289-
using the :attr:`TCPSite.port` property after the server has started.
1290-
1291-
For example::
1292-
1293-
app = web.Application()
1294-
runner = web.AppRunner(app)
1295-
await runner.setup()
1296-
site = web.TCPSite(runner, 'localhost', 0)
1297-
await site.start()
1298-
1299-
print(f"Server started on port {site.port}")
1300-
while True:
1301-
await asyncio.sleep(3600) # sleep forever
1302-
13031282
CORS support
13041283
------------
13051284

docs/web_reference.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,22 @@ application on specific TCP or Unix socket, e.g.::
29402940
This attribute is only guaranteed to be correct after the server has
29412941
been started.
29422942

2943+
When deploying aiohttp with zero-configuration networking, it may be
2944+
useful to have the server bind to a dynamic port. This can be done by
2945+
using the ``0`` port number, which causes the OS to assign a free port.
2946+
The assigned port can be retrieved using this attribute after the server
2947+
has started::
2948+
2949+
app = web.Application()
2950+
runner = web.AppRunner(app)
2951+
await runner.setup()
2952+
site = web.TCPSite(runner, 'localhost', 0)
2953+
await site.start()
2954+
2955+
print(f"Server started on port {site.port}")
2956+
while True:
2957+
await asyncio.sleep(3600) # sleep forever
2958+
29432959

29442960
.. class:: UnixSite(runner, path, *, \
29452961
shutdown_timeout=60.0, ssl_context=None, \

0 commit comments

Comments
 (0)