Skip to content

Commit

Permalink
Walk via multiple-threads (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua authored Nov 23, 2024
1 parent 84ec6a6 commit 38a236c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tosfs/compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""The compatible module about AbstractFileSystem in fsspec."""
import os
import re
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any, Optional, Union

from fsspec import AbstractFileSystem
Expand Down Expand Up @@ -194,14 +195,21 @@ def walk( # noqa
yield path, dirs, files
return

for d in dirs:
yield from self.walk(
full_dirs[d],
maxdepth=maxdepth,
detail=detail,
topdown=topdown,
**kwargs,
)
with ThreadPoolExecutor() as executor:
futures = {
executor.submit(
self.walk,
full_dirs[d],
maxdepth=maxdepth,
detail=detail,
topdown=topdown,
**kwargs,
): d
for d in dirs
}
for future in as_completed(futures):
for result in future.result():
yield result

if not topdown:
# Yield after recursion if walking bottom up
Expand Down

0 comments on commit 38a236c

Please sign in to comment.