Python recursion limit

前端 未结 3 1104
太阳男子
太阳男子 2021-01-23 17:54

So I understand the reason for the recursion limit of 1000. I want to run a script continuously, but am I right understanding that eventually the recursion limit will be reache

3条回答
  •  忘了有多久
    2021-01-23 18:36

    CPython has no optimizations for recursion, so you really want to avoid deeply-recursive code in favor of regular loops:

    def main():
        while True:
            all_files = getFiles(LOC_DIR)
            files = []
            for f in all_files:
                if checkExt(f):
                    files.append(f)
            if len(files) == 1:
                printLog('<<< Found %s matching file >>>' % len(files))
            elif len(files) > 1:
                printLog('<<< Found %s matching files >>>' % len(files))
            for f in files:
                if checkSize(f):
                    rsyncFile(f)
            printLog('No files found.  Checking again in %s seconds' % RUN_INT)
            time.sleep(RUN_INT)
            printLog('Checking for files')
    
    if __name__ == "__main__":    
        main()
    

提交回复
热议问题