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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:27:06+00:00 2026-05-31T12:27:06+00:00

I created 10000 files – my default limit was ulimit -n 1024 – I

  • 0

I created 10000 files – my default limit was ” ulimit -n 1024″ – I expected following script to fail with a message like “Too many files open” , but it didn’t fail. (/tmp/files has 10000 files)

Any thoughts on where am i going wrong?

import os
listfiles=os.listdir('/tmp/files')
count=0
f=''
for file in listfiles:
        fn=f+str(count)
        fn=open(file,'w')
        fn.write('hello')
        print 'file=',file
        count=count+1

print count
  • 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-31T12:27:08+00:00Added an answer on May 31, 2026 at 12:27 pm
    for file in listfiles:
            fn = f+str(count)    # what is this supposed to do?
            fn = open(file,'w')  # old file handle gets garbage collected and closed
            fn.write('hello')
            print 'file=',file
            count = count + 1
    

    Every time you rebind fn the previous file gets closed. It’s possible that in jython for example the file doesn’t get closed immediately, but it very likely will still be garbarge collected and closed before you exceed the 1024 file limit

    Try storing the file objects in a list like this:

    import os
    listfiles = os.listdir('/tmp/files')
    count = 0
    f = ''
    fn = []
    for file in listfiles:
            fn.append(open(file,'w'))
            fn[-1].write('hello')
            print 'file=',file
            count = count + 1
    
    print count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the following two C++ files: Stack.cpp #include<iostream> using namespace std; const int
we are receiving about 10000 messages per hour. We store them as individual files
It's well known that in Windows a directory with too many files will have
At the moment I'm working on a system that caches dynamically created files, nothing
What contributes to the number of files that are created? I assume the number
I have a script which generates like 16000 html pages and saves it in
My problem is I got following encoding error while copying data from csv files
There are 2 forms. Form2 isn't auto-created. Form2:=TForm2.Create(Application); Form2.Show; If to do Sleep(10000); inside
I have the following files (Main window/UI): files UI: # -*- coding: utf-8 -*-
Looking for easiest way to do the following: I have created 10,000 unique QR-codes,

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.