Skip to content

Commit

Permalink
Walk via multiple-threads
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Nov 23, 2024
1 parent 84ec6a6 commit 1d1b526
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 1d1b526

Please sign in to comment.