This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kevin.kuan.trend
Recipients kevin.kuan.trend, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-10-14.04:52:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1602651124.31.0.715592568811.issue42031@roundup.psfhosted.org>
In-reply-to
Content
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.trend@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)
History
Date User Action Args
2020-10-14 04:52:04kevin.kuan.trendsetrecipients: + kevin.kuan.trend, paul.moore, tim.golden, zach.ware, steve.dower
2020-10-14 04:52:04kevin.kuan.trendsetmessageid: <1602651124.31.0.715592568811.issue42031@roundup.psfhosted.org>
2020-10-14 04:52:04kevin.kuan.trendlinkissue42031 messages
2020-10-14 04:52:03kevin.kuan.trendcreate