Hello, On Mon, 24 Oct 2016 18:38:20 +0200 Xavier Combelle <[email protected]> wrote:
> > > Yes, this is something that has to be fixed in asyncio docs. > > Protocols/transports are advanced low level concepts, you don’t > > need to even know about them to use asyncio programs. I’ll try to > > find some time to work on the docs before 3.6 is released... > > > > Yury > > If I don't mistake, that is the high level > apihttps://docs.python.org/3.6/library/asyncio-stream.html#tcp-echo-client-using-streams > looks like the api is different than sync ones (with notably one > reader and one writer) and that the loop is needed everywhere .read() and .write() are generic methods of Python's stream interface ("protocol"). Sadly, Python's sockets don't implement stream interface natively, but require converting to a stream with .makefile() method. So, you can consider that in the example above, asyncio.open_connection() does the same as socket().makefile(). Otherwise, it's the same as "sync ones". Except: > writer.write(message.encode()) In asyncio, asynchronous library, .write() is somehow synchronous. > data = yield from reader.read(100) .read() is expectedly asynchronous. > writer.close() .close() is somehow synchronous again. Pretty inconsistent. It was proposed to add an asynchronous .write method to asyncio (which would be called differently of course), but... -- Best regards, Paul mailto:[email protected]
