zhuyifei1999 added a comment.

I just realized that os.rename fails on windows if target exists, and os.replace does not exist on python 2. One might have to use os.unlink / os.remove then os.rename on windows. I guess it's safe to assume that the time difference be the calls should be small enough that no dump consumers are started. Example import mess:

try:
    from os import replace
except ImportError:   # py2
    if sys.platform == 'win32':
        import os
        def replace(src, dst):
            try:
                os.rename(src, dst)
            except OSError:
                os.remove(dst)
                os.rename(src, dst)
    else:
        from os import rename as replace

os.remove will still cause an error on windows if the file is in use, but I do not know of a way to workaround that.


TASK DETAIL
https://phabricator.wikimedia.org/T183675

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: zhuyifei1999
Cc: Framawiki, Aklapper, Xqt, jayvdb, siebrand, Zoranzoki21, eflyjason, pywikibot-bugs-list, zhuyifei1999, Bright1055, Toppole69, Mine0901, Jayprakash12345, Magul, Tbscho, MayS, Beeyan, Mdupont, JJMC89, MtDu, D3r1ck01, Avicennasis, Dalba, Masti, Alchimista, Rxy
_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to