-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Expose os.scandir through Trio's async filesystem API? #924
Comments
So there are a few things to figure out here, I think:
|
If you ask me, ;) I would say that the iterator-thing has to be sacrificed. I would exhaust the
Agree! It's not trivial, for them who use A
In my inner vision I see a ...the same methods and functions as os.DirEntry, but with all async functions coupled to a syncronous sibling method with almost the same name, that can be run without any task switching.
|
Note that if you want to do this right now, it's pretty simple: scandir_results = await trio.run_sync_in_worker_thread(list(os.scandir("/some/path")))
We have some precedent for this split – see The larger problem is that @Manganus Can you say more about what how you want to use |
My instincts point in this direction:
Then one actually has a choice: But scandir is far from a matter of life or death for me. And I have not yet made any attempt along the lines here. And I hope to stay on a slightly higher level than
I would avoid premature optimization and initially use And maybe I would use the flags:
|
Thanks! This seems to work:
It is more efficient to filter results from scandir than from listdir - not only in terms of time, but there are less opportunities to create bugs if I can use its cached results instead of creating own caches. |
Copying over a feature request from user "Manganus" on Discourse:
Since I, personally, hardly know how to write readable code, I regret that I won’t become a contributor to this project.
Anyway, I would love to learn how to wrap
os.scandir
, until someone (who knows how to write readable code) has incorporated it into trio.The way
trio.Path.iterdir
works would IMHO fit perfectly (given that I understand it right.) It seems to be an async constructor that callsos.listdir
in a worker thread and then returns a regular generator (that does the actual yielding of results).The main point is the
DirEntry
objects. 😉I guess the main problem is the caching of
DirEntry.stat()
. If the data is in cache, you don’t really wish to await the result. But if not, you wouldn’t wish to block the execution.The text was updated successfully, but these errors were encountered: