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

Operation conflict between time package and file #87531

Closed
Minaki mannequin opened this issue Mar 2, 2021 · 2 comments
Closed

Operation conflict between time package and file #87531

Minaki mannequin opened this issue Mar 2, 2021 · 2 comments
Labels
3.10 only security fixes build The build process and cross-build topic-IO

Comments

@Minaki
Copy link
Mannequin

Minaki mannequin commented Mar 2, 2021

BPO 43365
Nosy @terryjreedy, @minaki
Files
  • test.py: The following code can be run after commenting sleep, otherwise the file will always be empty
  • 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 2021-03-05.22:56:17.631>
    created_at = <Date 2021-03-02.10:43:49.915>
    labels = ['build', 'invalid', '3.10', 'expert-IO']
    title = 'Operation conflict between time package and file'
    updated_at = <Date 2021-03-05.22:56:17.629>
    user = 'https://github.com/Minaki'

    bugs.python.org fields:

    activity = <Date 2021-03-05.22:56:17.629>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-05.22:56:17.631>
    closer = 'terry.reedy'
    components = ['IO']
    creation = <Date 2021-03-02.10:43:49.915>
    creator = 'minaki_2525'
    dependencies = []
    files = ['49843']
    hgrepos = []
    issue_num = 43365
    keywords = []
    message_count = 2.0
    messages = ['387909', '388171']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'minaki_2525']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue43365'
    versions = ['Python 3.10']

    @Minaki Minaki mannequin added 3.8 only security fixes 3.9 only security fixes topic-IO build The build process and cross-build labels Mar 2, 2021
    @Minaki
    Copy link
    Mannequin Author

    Minaki mannequin commented Mar 2, 2021

    """In Python 3.9, the following code can be run after commenting sleep, otherwise the file will always be empty"""
    import time

    file=open("data.txt","a+")
    while True:
        time.sleep(0.00001)
        file.write("test\n")
        print("add over")

    @terryjreedy
    Copy link
    Member

    I unlinked the preliminary versions of the code minimized in the 3 post.

    The posted code is buggy: it opens a file and then start an infinite loop. It has to be interrupted someway, and the file may not be properly closed and flushed to disk. When I make the loop finite and explicitly close the file, or even better, use a 'with' statement, the file is written as expected. At least on Windows, it runs noticeably slower with the sleep because the minimum sleep is 1/16 second.

    Minaki, if you find a problem with unbuggy code, you can post and reopen. If you are a beginner who does not know about things like closing file, flushing to disk, and the with statement, you should post to a question and answer forum such as python-list and ask 'Is Python or my code buggy?'

    @terryjreedy terryjreedy added 3.10 only security fixes and removed 3.8 only security fixes 3.9 only security fixes labels Mar 5, 2021
    @terryjreedy terryjreedy changed the title Operation conflict between time package and file in python 3.8 3.9 Operation conflict between time package and file Mar 5, 2021
    @terryjreedy terryjreedy added invalid 3.10 only security fixes and removed 3.8 only security fixes 3.9 only security fixes labels Mar 5, 2021
    @terryjreedy terryjreedy changed the title Operation conflict between time package and file in python 3.8 3.9 Operation conflict between time package and file Mar 5, 2021
    @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
    3.10 only security fixes build The build process and cross-build topic-IO
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant