{"action":"created","issue":{"url":"https://api.github.com/repos/python/asyncio/issues/279","labels_url":"https://api.github.com/repos/python/asyncio/issues/279/labels{/name}","comments_url":"https://api.github.com/repos/python/asyncio/issues/279/comments","events_url":"https://api.github.com/repos/python/asyncio/issues/279/events","html_url":"https://github.com/python/asyncio/issues/279","id":109567036,"number":279,"title":"NIO for files","user":{"login":"1st1","id":239003,"avatar_url":"https://avatars.githubusercontent.com/u/239003?v=3","gravatar_id":"","url":"https://api.github.com/users/1st1","html_url":"https://github.com/1st1","followers_url":"https://api.github.com/users/1st1/followers","following_url":"https://api.github.com/users/1st1/following{/other_user}","gists_url":"https://api.github.com/users/1st1/gists{/gist_id}","starred_url":"https://api.github.com/users/1st1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/1st1/subscriptions","organizations_url":"https://api.github.com/users/1st1/orgs","repos_url":"https://api.github.com/users/1st1/repos","events_url":"https://api.github.com/users/1st1/events{/privacy}","received_events_url":"https://api.github.com/users/1st1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-10-02T20:34:59Z","updated_at":"2015-10-26T21:26:32Z","closed_at":null,"body":"I've seen a few discussions around lack of non-blocking file io support in asyncio.  Normally, we assume that disk io is fast and doesn't block, but there are use cases where it can block for a long time: \r\n\r\n* HDDs are still very common and widely used. Huge ones can be quite slow at random access.\r\n* Network filesystems - sshfs, nfs, aws ebs etc.\r\n\r\nA workaround is to use a threadpool for file io, but that's suboptimal since it's hard to interact with asyncio code.\r\n\r\n`libuv` library (the one that NodeJS is built on) uses threadpools internally, to provide non-blocking file io.\r\n\r\nI see three options for asyncio:\r\n\r\n1. Keep the status quo.  Advise users to either assume that disk io never blocks, or use threadpools.\r\n2. Provide a function that will return a pair of `(StreamReader, StreamWriter)`. Loop will use a threadpool to do the actual IO.\r\n3. Provide a file object with a similar API to FileIO, but with coroutines for most of its methods. Loop will use a threadpool to do the actual IO.\r\n\r\nIf (2) or (3) is acceptable, I volunteer to draft the initial implementation."},"comment":{"url":"https://api.github.com/repos/python/asyncio/issues/comments/151289476","html_url":"https://github.com/python/asyncio/issues/279#issuecomment-151289476","issue_url":"https://api.github.com/repos/python/asyncio/issues/279","id":151289476,"user":{"login":"1st1","id":239003,"avatar_url":"https://avatars.githubusercontent.com/u/239003?v=3","gravatar_id":"","url":"https://api.github.com/users/1st1","html_url":"https://github.com/1st1","followers_url":"https://api.github.com/users/1st1/followers","following_url":"https://api.github.com/users/1st1/following{/other_user}","gists_url":"https://api.github.com/users/1st1/gists{/gist_id}","starred_url":"https://api.github.com/users/1st1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/1st1/subscriptions","organizations_url":"https://api.github.com/users/1st1/orgs","repos_url":"https://api.github.com/users/1st1/repos","events_url":"https://api.github.com/users/1st1/events{/privacy}","received_events_url":"https://api.github.com/users/1st1/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T21:26:32Z","updated_at":"2015-10-26T21:26:32Z","body":"@gvanrossum What do you think about https://github.com/Tinche/aiofiles?  Its approach is very lean -- use singledispatch to wrap all kind of objects that `open()` returns, and wrap them with proxies that offload all blocking operations to the loop's executor.\r\n\r\nThe main advantage is that the API is essentially the same as regular Python io, you just have to use `await` or `yield from` for most calls.  Do you think this is a right way to go?"}}