@synchronizedDeferred(busy)
    @deferredAsThread
    def garbageCheck(self):
        """Check for file patterns that are removeable"""
        watchDict = copy.deepcopy(self.watchDict) #use locals for safety
        for directory,garbageList in watchDict.iteritems():
            if not os.path.exists(directory): continue
            for pattern,limit in garbageList:
                #blocking method in a thread
                self.cleanupLinks(directory)
                files = [os.path.join(directory,f) for f in os.listdir(directory) \
                        if re.search(pattern,f)]
                files = sorted(files)
                if int(limit) > len(files):
                    log('These files matched:\n\t%s' % '\n\t'.join(files))
                while len(files) > int(limit):
                    oldfile = files.pop(0)
                    log('Deleting %s' % oldfile)
                    if os.path.islink(oldfile): continue
                    if os.path.isdir(oldfile):
                        for base, dirs, myfiles in os.walk(oldfile, topdown=False):
                            for name in myfiles:
                                os.remove(os.path.join(base, name))
                            for name in dirs:
                                os.rmdir(os.path.join(base, name))
                        os.rmdir(oldfile)
                    else: os.unlink(oldfile)
            #blocking method in a thread
            self.cleanupLinks(directory)


    #this will block the reactor
dataset/ETHPy150Open OrbitzWorldwide/droned/droned/services/janitizer.py/Janitizer.garbageCheck/swapped operands of `>`