Skip to content

Path.iterdir/glob/rglob methods do not delegate file system calls to a thread #1308

Closed
@vxgmichel

Description

@vxgmichel

Notice how the actual iteration is not performed in the executor thread:

trio/trio/_path.py

Lines 56 to 62 in 20da9af

def iter_wrapper_factory(cls, meth_name):
@async_wraps(cls, cls._wraps, meth_name)
async def wrapper(self, *args, **kwargs):
meth = getattr(self._wrapped, meth_name)
func = partial(meth, *args, **kwargs)
items = await trio.to_thread.run_sync(func)
return (rewrap_path(item) for item in items)

Here's a possible fix:

 def iter_wrapper_factory(cls, meth_name): 
     @async_wraps(cls, cls._wraps, meth_name) 
     async def wrapper(self, *args, **kwargs): 
         meth = getattr(self._wrapped, meth_name) 
         func = partial(meth, *args, **kwargs) 
         items = await trio.to_thread.run_sync(lambda: list(func())) 
         return (rewrap_path(item) for item in items) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions