Nov-22-2019, 09:09 PM
for the main program, try running:
then try same with second script
import cprofile import os, time, shutil, tarfile #fnmatch from PIL import Image import shutil def main(): all_files=[] sext = [] temp = "" print(time.strftime("%H|%M|%S")) #chiedo all'utente che estensioni vuole cercare, in questo caso a me interessano i jpg, quindi inserisco: .jpg #dopo aver scelto le estensioni, scrivo 0 e invio while True: sext.append(input("cerca: ")) if sext[-1] == "0": del sext[-1] break sext = tuple(sext) #naviga fra le cartelle di Files recuperati, e cerca tutti i file che finiscono con "sext", รจ una tupla di estensioni, in questo caso, mi interessa solo ".jpg" for parent, directories, filenames in os.walk("/media/mionomeutente/PENNA USB/Files recuperati"): for x in filenames: if x.endswith(sext): fileDaAnalizzare = parent+'/'+x #apre il file con estensione specificata, e verifica che l'immagine abbia una certa grandezza try: im = Image.open(fileDaAnalizzare) width, height = im.size if(width > 350 and height >350): document_path = os.path.join(parent,x) print(document_path) #copio semplicemente l'immagine che rispetta le mie esigenze nella cartella grandi shutil.copy(document_path, '/media/mionomeutente/PENNA USB/grandi') except: pass print(time.strftime("%H|%M|%S")) if __name__ == '__main__': cProfile.run('main()')And see if you can identify the bottleneck.
then try same with second script