Skip to content

Instantly share code, notes, and snippets.

@cemdrk
Created September 29, 2019 10:18
Show Gist options
  • Save cemdrk/8ec6e483c37553dfd927277a939fd945 to your computer and use it in GitHub Desktop.
Save cemdrk/8ec6e483c37553dfd927277a939fd945 to your computer and use it in GitHub Desktop.
List Files with timeout
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