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: tcp_echo_client in asyncio streams example does not work. Hangs for ever at reaser.read()
Type: behavior Stage: patch review
Components: asyncio Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, jaswdr, jcolo, yselivanov
Priority: normal Keywords: patch

Created on 2021-04-06 08:07 by jcolo, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 25889 closed jaswdr, 2021-05-04 11:48
Messages (4)
msg390295 - (view) Author: julian colomina (jcolo) Date: 2021-04-06 08:07
taking the example verbatim into an ubuntu 20.04 with
 Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux

will hand indefinitely at 
data = await reader.read(100)

changing for 
data = await asyncio.wait_for(reader.read(100),5)

will always leave on timeout.
msg392833 - (view) Author: Jonathan Schweder (jaswdr) * Date: 2021-05-03 18:49
I was able to execute the example in Debian 10 + Python 3.10+

Did you execute the server too? You need to create two files, one for the client code and one for the server code, the server as specified by the example should be something like the code below, try to save it to a file, then execute it, after that execute the client example that you have cited.

import asyncio

async def handle_echo(reader, writer):
    data = await reader.read(100)
    message = data.decode()
    addr = writer.get_extra_info('peername')

    print(f"Received {message!r} from {addr!r}")

    print(f"Send: {message!r}")
    writer.write(data)
    await writer.drain()

    print("Close the connection")
    writer.close()

async def main():
    server = await asyncio.start_server(
        handle_echo, '127.0.0.1', 8888)

    addr = server.sockets[0].getsockname()
    print(f'Serving on {addr}')

    async with server:
        await server.serve_forever()

asyncio.run(main())
msg392841 - (view) Author: julian colomina (jcolo) Date: 2021-05-03 21:00
@jaswdr

Thanks for your response.

No I did not run the server that you mention. 

The language made me imply that the same process, in two separate coroutines, would be writing/reading from each end of the tcp connection. One writing to the tcp buffer, the second one draining it.

If  the intended usage is as you explain, please close the issue.

My bad, sorry.

JC
msg392858 - (view) Author: Jonathan Schweder (jaswdr) * Date: 2021-05-04 08:04
@jcolo

Awesome to hear that you were able to run the example, in fact I got in the same trap, thinking the same that the example should carry the server and client side, I guess we can improve the documentation to avoid it, I'll sent a PR to make the improvement.
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87908
2021-05-04 11:48:05jaswdrsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24563
2021-05-04 08:04:56jaswdrsetmessages: + msg392858
2021-05-03 21:00:39jcolosetmessages: + msg392841
2021-05-03 18:49:51jaswdrsetnosy: + jaswdr
messages: + msg392833
2021-04-06 08:07:33jcolocreate