On Mon, Mar 23, 2015 at 8:39 PM, Tin Tvrtković <tinches...@gmail.com> wrote: > f = yield from aiofiles.open('test.bin', mode='rb') > try: > data = yield from f.read(512) > finally: > yield from f.close() > > I've run into two difficulties - first, it's difficult for me to tell which > calls may actually block (does 'isatty' block? does 'seekable' block [I > think so]?) and which don't have to go through an executor. But this is a > question for another day. :)
On Mon, Mar 23, 2015 at 8:39 PM, Tin Tvrtković <tinches...@gmail.com> wrote: > f = yield from aiofiles.open('test.bin', mode='rb') > try: > data = yield from f.read(512) > finally: > yield from f.close() That's awesome, Tin! > I've run into two difficulties - first, it's difficult for me to tell which > calls may actually block (does 'isatty' block? does 'seekable' block [I > think so]?) and which don't have to go through an executor. But this is a > question for another day. :) I'd recommend taking a look at the Node.js filesystem API. Their philosophy is: anything that needs to go to disk is blocking, and everything that is blocking must have a callback. Just look at the API for their fs module: https://nodejs.org/api/fs.html For convenience, some functions have a non-callback "synchronous" version. Those have a Sync suffix, e.g. fs.stat(path, callback) fs.statSync(path) Cheers, Luciano -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Professor em: http://python.pro.br | Twitter: @ramalhoorg