This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: convenience of using create_datagram_endpoint (and friends)
Type: enhancement Stage:
Components: asyncio Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Roman.Valov, asvetlov, yselivanov
Priority: normal Keywords:

Created on 2021-03-24 20:18 by Roman.Valov, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
async.py Roman.Valov, 2021-03-24 20:18
Messages (1)
msg389488 - (view) Author: Roman Valov (Roman.Valov) Date: 2021-03-24 20:18
Please check the attached source code.

I have to implement an UDP server listening on all interfaces and able to detect what is the local address is used to communicate with remote address. In order to do this I'm using a temporary socket connected to exact remote endpoint to retrieve it's sock name.

When I implement the solution in a pure `asyncio` fashion I faced pair of inconveniences:

ISSUE-1: there is no idiomatic way to sleep forever inside async function. The example of using `create_datagram_endpoint` in documentation uses `sleep(3600)` which is not so useful. I've used `loop.create_future()` but it's perceived to be kind of hack. Also I can't use `loop.run_forever` in this context.

Possible solutions:
 - `serve_forever` for a transport object
 - `asyncio.setup_and_run_forever(main())` -- function to setup file descriptors for an event loop and run forever.
 - `asyncio.sleep(None)` or `asyncio.pause()` -- special argument for sleep or dedicated `pause` function.


ISSUE-2: callbacks for `Protocol` class are assumed to be sync `def`s. Despite the class is designed to be used as a part of `asyncio`. So, in order to invoke async code from sync callback I have to add some boilerplate code. Compare with `start_server`. It's `client_connected_cb` argument maybe a plain callable or co-routine function. So it's proposed to let Protocol callbacks to be `async def`s.
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87785
2021-03-24 20:18:16Roman.Valovcreate