New submission from Kevin Kuan <kevin.kuan.tr...@gmail.com>:
Hi, I would like to report bug for os.makedirs(). I am running this script on Windows 10 1909 (most win10 work), python 3.8.1. os.makedirs() is making explorer.exe huge amount of memory and crashing the system after only 3 hours. After changing that line to subprocess.run('mkdir ...') memory usage is reduced significantly.After changing all shutil functions as well, memory usage will not grow. (This is my first time community contribution. If anything, please let me know.) Kevin Kuan (kevin.kuan.tr...@gmail.com) -------script.txt------ import time import logging import uuid import subprocess REPEAT = 10 def new_target_folder(): TARGET_BASE, str(uuid.uuid4().hex) ) os.makedirs(target) return target def delete_folder(target): if os.path.exists(target): shutil.rmtree(target) def copy_samples(target): shutil.copytree( SOURCE_FOLDER, os.path.join(target, 'file_copy_clean_samples') def copy_file_test(): for i in range(REPEAT): t = new_target_folder() copy_samples(t) delete_folder(t) ------after.txt------ import os import shutil import time import logging import uuid import subprocess REPEAT = 10 SOURCE_FOLDER = os.path.abspath( os.path.join( __file__, '..', '..', '_VolumeTestSamples', 'file_copy_clean_samples', ) ) TARGET_BASE = os.path.join( os.environ['USERPROFILE'], r'Desktop', r'sample_file_copy', str(uuid.uuid4().hex) ) PAUSE = 1 def run_for_one_week(func, pause): time_start = time.time() while True: time_now = time.time() logging.debug('{}'.format(time_now)) if time_now - time_start > 1 * 7 * 24 * 60 * 60: break func() time.sleep(pause) def new_target_folder(): target = os.path.join( TARGET_BASE, str(uuid.uuid4().hex) ) subprocess.run( ['mkdir', target], shell=True ) return target def delete_folder(target): if os.path.exists(target): subprocess.run( ['rmdir', '/s', '/q', target], shell=True ) def copy_samples(target): subprocess.run( ['echo', 'D', '|', 'xcopy', '/s', '/y', SOURCE_FOLDER, target], shell=True ) def copy_file_test(): for i in range(REPEAT): t = new_target_folder() print (t) copy_samples(t) delete_folder(t) if __name__ == '__main__': r = logging.getLogger() r.setLevel(logging.DEBUG) run_for_one_week(copy_file_test, PAUSE) ---------- components: Windows files: Image20201014125025.png messages: 378603 nosy: kevin.kuan.trend, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: os.makedirs() introduces high memory usage for explorer.exe versions: Python 3.8 Added file: https://bugs.python.org/file49519/Image20201014125025.png _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42031> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com