[New-bugs-announce] [issue43619] convenience of using create_datagram_endpoint (and friends)

Roman Valov report at bugs.python.org
Wed Mar 24 16:18:16 EDT 2021


New submission from Roman Valov <reddot.rocks at gmail.com>:

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.

----------
components: asyncio
files: async.py
messages: 389488
nosy: Roman.Valov, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: convenience of using create_datagram_endpoint (and friends)
type: enhancement
versions: Python 3.8
Added file: https://bugs.python.org/file49912/async.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43619>
_______________________________________


More information about the New-bugs-announce mailing list