Created
September 29, 2019 10:18
-
-
Save cemdrk/8ec6e483c37553dfd927277a939fd945 to your computer and use it in GitHub Desktop.
List Files with timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread, Event | |
import time | |
path = '/dbfs/databricks-datasets/' | |
stop_event = Event() | |
files = [] | |
def find_files(path): | |
for i in os.listdir(path): | |
full_path = os.path.join(path, i) | |
if os.path.isfile(full_path): | |
files.append(full_path) | |
elif os.path.isdir(full_path): | |
find_files(full_path) | |
if stop_event.is_set(): | |
break | |
if __name__ == '__main__': | |
action_thread = Thread(target=find_files, args=(path,)) | |
action_thread.start() | |
action_thread.join(timeout=5) | |
stop_event.set() | |
for f in files: | |
print(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment