Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3630198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:14:22+00:00 2026-05-19T00:14:22+00:00

here’s my question: I’m writing a script to check if my website running all

  • 0

here’s my question: I’m writing a script to check if my website running all right, the basic idea is to get the server response time and similar stuff every 5 minutes or so, and the script will log the info each time after checking the server status. I know it’s no good to close the script while it’s in the middle of checking/writing logs, but I’m curious if there are lots of server to check and also you have to do the file I/O pretty frequently, what would happen if you abruptly close the script?

OK, here’s an example:

while True:
    DemoFile = open("DemoFile.txt", "a")
    DemoFile.write("This is a test!")
    DemoFile.close()

    time.sleep(30)

If I accidentally close the script while this line DemoFile.write("This is a test!") is running, what would I get in the DemoFile.txt? Do I get “This i”(an incomplete line) or the complete line or the line not even added?

Hopefully somebody knows the answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:14:23+00:00Added an answer on May 19, 2026 at 12:14 am

    According to the python io documentation, buffering is handled according to the buffering parameter to the open function.

    The default behavior in this case would be either the device’s block size or io.DEFAULT_BUFFER_SIZE if the block size can’t be determined. This is probably something like 4096 bytes.

    In short, that example will write nothing. If you were writing something long enough that the buffer was written once or twice, you’d have multiples of the buffer size written. And you can always manually flush the buffer with flush().

    (If you specify buffering as 0 and the file mode as binary, you’d get “This i”. That’s the only way, though)

    As @sven pointed out, python isn’t doing the buffering. When the program is terminated, all open file descriptors are closed and flushed by the operating system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here the total height of all <div> 's are 900 pixels, but the jQuery
Here's the basic setup: I have a thin bar at the top of a
Here is a simple timepicker to jQuery UI's datepicker <script type=text/javascript> /* <![CDATA[ */
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is the scenario: I'm writing an app that will watch for any changes
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here an example of my checkbox list http://jsfiddle.net/YnM2f/ Let's say I check on G
Here a simple question : What do you think of code which use try
Here is my question. I am having this simple menu. <div id=menu> <ul> <li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.