Mar-11-2021, 05:04 PM
I have the following function that builds a file list.
import os import fnmatch import threading def getFiles(root='.', pattern='*.*', recurse=False): results = [] if recurse: for base, dirs, files in os.walk(root): match = fnmatch.filter(files, pattern) results.extend(os.path.join(base, f) for f in match) else: results = fnmatch.filter(os.listdir(root),pattern) for i in range(0, len(results)): results[i] = os.path.join(root,results[i]) return resultsI want to run this function in a thread so that it can build the file list while the script is busy doing other things. How can I get the returned list from the main script? Here is a stripped down version.
#Create the thread and start parallel execution t = threading.Thread(target=getFiles, args=['.', '*', False], daemon=False) t.start() #Here's where I do the "other things" # Done other things. Wait for the file list thread to complete t.join()How do I get the returned list? I have found several examples but none that are not obfuscated by irrelevant bells and whistles.