Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trio file io on asyncio #194

Closed
buhman opened this issue Jun 10, 2017 · 4 comments
Closed

trio file io on asyncio #194

buhman opened this issue Jun 10, 2017 · 4 comments

Comments

@buhman
Copy link
Member

buhman commented Jun 10, 2017

Would it be worthwhile to add subprojects under python-trio for various popular APIs
… gain the ability to run in "trio mode",

Not to suggest refactoring this all over again, but I've been thinking about #105 and #171. I think the _file_io stuff is actually pretty re-usable, even for asyncio (definitely much less scary than aiofiles anyway).

What do you think about ripping all of this back out, then making a python-trio/threaded-file-io or similar that supports creating both asyncio and trio threads (which I think is a fourth variant of #171 called *-libs-on-*, which we could also maybe apply to things like the stream API from #107).

@buhman
Copy link
Member Author

buhman commented Jun 10, 2017

I'm not sure if this makes it too complicated, but I was thinking the new library would provide something like:

def open_file_factory(thread_factory):
    …
    return open_file_that_uses_thread_factory

Then trio has a new extras dependency on the threaded-file-io library, and trio._file_io gets replaced with:

if threaded_file_io_available:
    __all__ += ['open_file']
    open_file = open_file_factory(thread_factory=trio.run_in_worker_thread)

Then it's just:

pip install trio[threaded_file_io]

@njsmith
Copy link
Member

njsmith commented Jun 11, 2017

Whoops, I got confused about github's threading, and accidentally replied to this on the PR: #180 (comment)

@buhman
Copy link
Member Author

buhman commented Jun 12, 2017

but we failed to do so because we got distracted with other things and now no-one will ever know

Welp, I don't want to be that guy.

@buhman buhman closed this as completed Jun 12, 2017
@njsmith
Copy link
Member

njsmith commented Jun 12, 2017

Welp, I don't want to be that guy.

Sorry if I came over too intense there! If you want to make an asyncio library you should totally do that. I'm just trying to explain where my sometimes idiosyncratic opinions come from, personally :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants