I want to make a class that will run in a separate thread and delete the subdirectories in a separate directory depending on the time of the last subdirectory change. Is it safe to do this in a separate thread?

How to organize search and delete directories depending on time? This is how an error occurs:

def run(self): for current_directory, directories, files in os.walk(self.directory): print(current_directory) print(os.path.getatime(current_directory) - datetime.datetime.now()) 

    1 answer 1

    time.gmtime

     import os import time def run(directory=os.getcwd()): for current_directory, directories, files in os.walk(directory): t = os.path.getatime(current_directory) tg = time.gmtime(t) print(tg) print(tg.tm_year, tg.tm_min) run() 

    you can delete in the stream without problems

    • Yes, you can delete. But I still use different libraries, for example, os from several threads. Isn't that scary? - faoxis
    • one
      No, well, only if you do something from different threads with the same object, then you need something like quizful.net/post/thread-synchronization-in-python - vadim vaduxa