Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing a pyc file is not atomic under Windows #57601

Closed
pitrou opened this issue Nov 13, 2011 · 5 comments
Closed

Writing a pyc file is not atomic under Windows #57601

pitrou opened this issue Nov 13, 2011 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@pitrou
Copy link
Member

pitrou commented Nov 13, 2011

BPO 13392
Nosy @brettcannon, @ncoghlan, @pitrou, @vstinner, @bitdancer
Files
  • winimport.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-11-15.18:21:20.405>
    created_at = <Date 2011-11-13.01:20:52.168>
    labels = ['interpreter-core']
    title = 'Writing a pyc file is not atomic under Windows'
    updated_at = <Date 2011-11-15.19:48:03.615>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2011-11-15.19:48:03.615>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-15.18:21:20.405>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2011-11-13.01:20:52.168>
    creator = 'pitrou'
    dependencies = []
    files = ['23674']
    hgrepos = []
    issue_num = 13392
    keywords = ['patch']
    message_count = 5.0
    messages = ['147540', '147690', '147693', '147694', '147700']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'pitrou', 'vstinner', 'r.david.murray', 'neologix', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13392'
    versions = ['Python 3.3']

    @pitrou
    Copy link
    Member Author

    pitrou commented Nov 13, 2011

    bpo-13146 solved the issue of writing pyc files under POSIX. Under Windows, the problem still exists, as the following buildbot failure shows:

    [317/360] test_multiprocessing
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\multiprocessing\forking.py", line 373, in main
        prepare(preparation_data)
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\multiprocessing\forking.py", line 499, in prepare
        '__parents_main__', file, path_name, etc
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\regrtest.py", line 175, in <module>
        import packaging.command
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\packaging\command\__init__.py", line 4, in <module>
        from packaging.util import resolve_name
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\packaging\util.py", line 5, in <module>
        import csv
    EOFError: EOF read where not expected
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\multiprocessing\forking.py", line 373, in main
        prepare(preparation_data)
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\multiprocessing\forking.py", line 499, in prepare
        '__parents_main__', file, path_name, etc
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\regrtest.py", line 175, in <module>
        import packaging.command
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\packaging\command\__init__.py", line 4, in <module>
        from packaging.util import resolve_name
      File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\packaging\util.py", line 5, in <module>
        import csv
    EOFError: EOF read where not expected
    [etc.]

    (from http://www.python.org/dev/buildbot/all/builders/x86%20XP-4%203.x/builds/5551/steps/test/logs/stdio)

    Attached patch uses MoveFileEx to perform a (hopefully atomic) rename from a temporary file when creating the pyc file.
    The same strategy cannot be created for importlib since MoveFileEx isn't exposed at the Python level (we could delete the tmp file if renaming fails, though; it simply means another process beat us to it, which shouldn't be a problem here).

    @pitrou pitrou added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 13, 2011
    @brettcannon
    Copy link
    Member

    I say go with the deletion for importlib. If the failure is a sign of success, then just go with it and not worry about the failure. __pycache__ guarantees that we are not losing out by clobbering some other Python version's pyc file.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 15, 2011

    New changeset b75b41237380 by Antoine Pitrou in branch 'default':
    Issue bpo-13392: Writing a pyc file should now be atomic under Windows as well.
    http://hg.python.org/cpython/rev/b75b41237380

    @pitrou
    Copy link
    Member Author

    pitrou commented Nov 15, 2011

    Ok, done. Let's see if that fixes the sporadic failures on the buildbots.

    @pitrou pitrou closed this as completed Nov 15, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 15, 2011

    New changeset 12940d9f8031 by Antoine Pitrou in branch 'default':
    Fix regression under Windows following b75b41237380 (from issue bpo-13392)
    http://hg.python.org/cpython/rev/12940d9f8031

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants