processes and threading each key of the data default dictionary is -tuple of (sizefilename)where the filename does not include the pathand each value is list of filenames (which do include their pathsany items whose value list has more than one filename potentially has duplicates the dictionary is populated by iterating over all the files in the given pathbut skipping any files we cannot get the size of (perhaps due to permissions problemsor because they are not normal files)and any that are of size (since all zero length files are the samework_queue queue priorityqueue(results_queue queue queue(md _from_filename {for in range(opts count)number "{ }format( if opts debug else "worker worker(work_queuemd _from_filenameresults_queuenumberworker daemon true worker start(with all the data in place we are ready to create the worker threads we begin by creating work queue and results queue the work queue is priority queueso it will always return the lowest-priority items (in our case the smallest filesfirst we also create dictionary where each key is filename (including its pathand where each value is the file' md digest value the purpose of the dictionary is to ensure that we never compute the md of the same file more than once (since the computation is expensivewith the shared data collections in place we loop as many times as there are threads to create (by defaultseven timesthe worker subclass is similar to the one we created beforeonly this time we pass both queues and the md dictionary as beforewe start each worker straight away and each will be blocked until work item becomes available results_thread threading threadtarget=lambdaprint_results(results_queue)results_thread daemon true results_thread start(rather than creating threading thread subclass to process the results we have created function and we pass that to threading thread(the return value is custom thread that will call the given function once the thread is started we pass the results queue (which isof courseempty)so the thread will block immediately at this point we have created all the worker threads and the results thread and they are all blocked waiting for work for sizefilename in sorted(data)