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 8970155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:41:32+00:00 2026-06-15T17:41:32+00:00

I need to setup some test conditions to simulate a filled up disk. I

  • 0

I need to setup some test conditions to simulate a filled up disk. I created the following to simply write garbage to the disk:

#!/usr/bin/python

import os
import sys
import mmap

def freespace(p):
    """
    Returns the number of free bytes on the drive that ``p`` is on
    """
    s = os.statvfs(p)
    return s.f_bsize * s.f_bavail 

if __name__ == '__main__':

    drive_path = sys.argv[1]
    output_path = sys.argv[2]

    output_file = open(output_path, 'w')

    while freespace(drive_path) > 0:
        output_file.write("!")
        print freespace(drive_path)
        output_file.flush()

    output_file.close()

As far as I can tell by looking at the return value from freespace, the write method does not write the file to until it is closed, thereby making the while condition invalid.

Is there a way I can write the data directly to the file? Or another solution perhaps?

  • 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-06-15T17:41:32+00:00Added an answer on June 15, 2026 at 5:41 pm

    This is untested but I imagine something along these lines will be the quickest way to fill the disk easily

    import sys
    import errno
    
    write_str = "!"*1024*1024*5  # 5MB
    
    output_path = sys.argv[1]
    
    with open(output_path, "w") as f:
        while True:
            try:
                f.write(write_str)
                f.flush()
            except IOError as err:
                if err.errno == errno.ENOSPC:
                    write_str_len = len(write_str)
                    if write_str_len > 1:
                        write_str = write_str[:write_str_len/2]
                    else:
                        break
                else:
                    raise
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to investigate/test the behavior of some code on Linux under conditions where
I have some code I need to write a test for that connects to
I need to setup some 301 permanent redirects in the web.config of an ASP.NET
I need to setup NACHOS java version in Linux and run some simple sample
I need some advice of how to setup my tables I currently have a
I have some expensive test setup that is only necessary for a handful of
I need to setup a custom action within WiX 3.0. I have the following
I need a public WCF service to test against. I would like some basic
I have a scenario setup where I need to test to see if the
I need to test some function, that needs my application's database and context. I

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.