Message393584
The original problem can be fixed by wrapping await into try-except block:
```
async def create_connection(ssl_obj):
loop = asyncio.get_event_loop()
connector = loop.create_connection(MyEchoClientProtocol, '127.0.0.1', 5000, ssl=ssl_obj)
connector = asyncio.ensure_future(connector)
try:
tr, pr = await connector
except asyncio.CancelledError:
if connector.done():
tr, pr = connector.result()
# Uncommenting the following line fixes the problem:
# tr.close()
raise
return tr, pr
```
I've updated my example to reproduce this: https://github.com/ods/bpo-37658/commit/eca3d81d60cbe129ce687674e6451836d567f6b9
I believe it's general problem with maintaining atomicity in async code, and not a bug in `wait_for`. Probably having an interface like `async with loop.create_connection(…) as transport, protocol` might simplify correct usage for this particular case. |
|
Date |
User |
Action |
Args |
2021-05-13 14:53:36 | ods | set | recipients:
+ ods, asvetlov, chris.jerdonek, Elvis.Pranskevichus, lukasz.langa, yselivanov, miss-islington, Nikita Ilyasov, aaliddell |
2021-05-13 14:53:36 | ods | set | messageid: <1620917616.4.0.310145765203.issue37658@roundup.psfhosted.org> |
2021-05-13 14:53:36 | ods | link | issue37658 messages |
2021-05-13 14:53:36 | ods | create | |
|