cannot open file in write mode, no such file or directory

Discussion in 'Python' started by haynesc@gmail.com, Feb 28, 2005.

  1. Guest

    Hi,

    I'm having a problem where when trying to open a file in write mode, I
    get an IOError stating no such file or directory. I'm calling an
    external program which takes an input file and produces an output file
    repeatedly, simulating the input file separately for each replicate.
    The error occurs when trying to open the input file to write out the
    new data. The problem is difficult to reproduce since it only shows up
    once every few thousand replicates. I've tried using both os.system
    and os.popen to invoke the external program. Originally I was running
    this on cygwin, but also tried under windows.

    I'm confused as to why the error would state no such file when opening
    in write mode, it should just create the file if it can't find it. I
    imagine it has something to do with the external program (its mostly
    likely not written very well), but I'm hoping theres a solution to this
    that doesn't involve modifying that program. Is it possible that the
    file isn't being closed properly? If so, how can I ensure it is
    available?

    Thanks
    , Feb 28, 2005
    #1
    1. Advertising

  2. Kartic Guest

    > I'm having a problem where when trying to open a file in write mode,
    I
    > get an IOError stating no such file or directory. I'm calling an
    > external program which takes an input file and produces an output

    file
    > repeatedly, simulating the input file separately for each replicate.
    > The error occurs when trying to open the input file to write out the
    > new data. The problem is difficult to reproduce since it only shows

    up
    > once every few thousand replicates. I've tried using both os.system


    I am afraid you need to give more information that just IOError,
    calling an external program.

    Please post the exact message including the input filename at the time
    the program went down. If you don't print the filename, please modify
    your program to do so.

    A shot in the dark solution to your problem might be that you are
    dynamically generating a filename and that filename probably contains
    characters not allowed by the local file system OR you generate a path
    that does not exist. For open() to work with the 'w' flag, the path
    where the file you say should be created should exist.

    Thanks,
    -Kartic
    Kartic, Feb 28, 2005
    #2
    1. Advertising

  3. Steve Holden Guest

    Kartic wrote:
    >>I'm having a problem where when trying to open a file in write mode,

    >
    > I
    >
    >>get an IOError stating no such file or directory. I'm calling an
    >>external program which takes an input file and produces an output

    >
    > file
    >
    >>repeatedly, simulating the input file separately for each replicate.
    >>The error occurs when trying to open the input file to write out the
    >>new data. The problem is difficult to reproduce since it only shows

    >
    > up
    >
    >>once every few thousand replicates. I've tried using both os.system

    >
    >
    > I am afraid you need to give more information that just IOError,
    > calling an external program.
    >
    > Please post the exact message including the input filename at the time
    > the program went down. If you don't print the filename, please modify
    > your program to do so.
    >
    > A shot in the dark solution to your problem might be that you are
    > dynamically generating a filename and that filename probably contains
    > characters not allowed by the local file system OR you generate a path
    > that does not exist. For open() to work with the 'w' flag, the path
    > where the file you say should be created should exist.
    >

    Another low-probability cause is that you are trying to create files in
    a non-existent directory.

    regards
    Steve
    Steve Holden, Feb 28, 2005
    #3
  4. Guest

    Kartic wrote:
    > > I'm having a problem where when trying to open a file in write

    mode,
    > I
    > > get an IOError stating no such file or directory. I'm calling an
    > > external program which takes an input file and produces an output

    > file
    > > repeatedly, simulating the input file separately for each

    replicate.
    > > The error occurs when trying to open the input file to write out

    the
    > > new data. The problem is difficult to reproduce since it only

    shows
    > up
    > > once every few thousand replicates. I've tried using both

    os.system
    >
    > I am afraid you need to give more information that just IOError,
    > calling an external program.
    >
    > Please post the exact message including the input filename at the

    time
    > the program went down. If you don't print the filename, please modify
    > your program to do so.
    >
    > A shot in the dark solution to your problem might be that you are
    > dynamically generating a filename and that filename probably

    contains
    > characters not allowed by the local file system OR you generate a

    path
    > that does not exist. For open() to work with the 'w' flag, the path
    > where the file you say should be created should exist.
    >
    > Thanks,
    > -Kartic


    Sorry, here is the exact error:

    Traceback (most recent call last):
    File "hapSim.py", line 415, in ?
    run(REPLICATES, dsSelection, permuteStatus, sigThreshold
    File "hapSim.py", line 354, in run
    createInput(dt)
    File "hapSim.py", line 178, in createInput
    inF = open(IN_FNAME, "w")
    IOError: [Errno 2] No such file or directory: 'prog.input'

    I am using the same file name repeatedly, it works fine the first few
    thousand times, but eventually gives this error.
    , Feb 28, 2005
    #4
  5. Kartic Guest

    Could you please post your entire program, if possible?

    Thanks!
    Kartic, Feb 28, 2005
    #5
  6. John Machin Guest

    wrote:
    > Kartic wrote:
    > > > I'm having a problem where when trying to open a file in write

    > mode,
    > > I
    > > > get an IOError stating no such file or directory. I'm calling an
    > > > external program which takes an input file and produces an output

    > > file
    > > > repeatedly, simulating the input file separately for each

    > replicate.
    > > > The error occurs when trying to open the input file to write out

    > the
    > > > new data. The problem is difficult to reproduce since it only

    > shows
    > > up
    > > > once every few thousand replicates. I've tried using both

    > os.system
    > >
    > > I am afraid you need to give more information that just IOError,
    > > calling an external program.
    > >
    > > Please post the exact message including the input filename at the

    > time
    > > the program went down. If you don't print the filename, please

    modify
    > > your program to do so.
    > >
    > > A shot in the dark solution to your problem might be that you are
    > > dynamically generating a filename and that filename probably

    > contains
    > > characters not allowed by the local file system OR you generate a

    > path
    > > that does not exist. For open() to work with the 'w' flag, the path
    > > where the file you say should be created should exist.
    > >
    > > Thanks,
    > > -Kartic

    >
    > Sorry, here is the exact error:
    >
    > Traceback (most recent call last):
    > File "hapSim.py", line 415, in ?
    > run(REPLICATES, dsSelection, permuteStatus, sigThreshold
    > File "hapSim.py", line 354, in run
    > createInput(dt)
    > File "hapSim.py", line 178, in createInput
    > inF = open(IN_FNAME, "w")
    > IOError: [Errno 2] No such file or directory: 'prog.input'
    >
    > I am using the same file name repeatedly, it works fine the first few
    > thousand times, but eventually gives this error.


    1. Exactly how many is "few thousand"? Is it the same number each time?
    Does the problem still happen if you don't run the external program,
    but just create the input file a few thousand times?

    2. Which version of Windows are you using, and what type of filesystem?
    When it dies, how many files exist in the directory where you are
    trying to create "prog.input"? Reason for asking: I vaguely recall
    problems with FAT-type filesystems where there was a rather low limit
    on the number of files that could be recorded in a directory, PLUS a
    rather misleading "errno" being returned when one hit the limit.
    John Machin, Feb 28, 2005
    #6
  7. David Bolen Guest

    writes:

    > I'm having a problem where when trying to open a file in write mode, I
    > get an IOError stating no such file or directory. I'm calling an
    > external program which takes an input file and produces an output file
    > repeatedly, simulating the input file separately for each replicate.
    > The error occurs when trying to open the input file to write out the
    > new data. The problem is difficult to reproduce since it only shows up
    > once every few thousand replicates. I've tried using both os.system
    > and os.popen to invoke the external program. Originally I was running
    > this on cygwin, but also tried under windows.


    You might be hitting a race condition where the OS is still
    considering the file to be in use when you get around to rewriting it,
    even if the using application has just exited. I've run into similar
    problems when trying to rename temporary files under NT based systems.

    The problem can be obscured because some of the Win32-specific IO
    errors can turn into more generic IOError exceptions at the Python
    level due to incomplete mappings available for all Win32 errors. In
    particular, a lot of Win32-layer failures turn into EINVAL errno's at
    the C RTL level, which Python in turn translates to ENOENT (which is
    the file not found). So the IOError exception at the Python level can
    be misleading.

    Since it sounds like you can reproduce the problem relatively easily
    (just run your application several thousand times), a quick check for
    this condition would be to trap the IOError, delay a few seconds (say
    5-10 to be absolutely sure, although in the cases I've run into 2-3 is
    generally more than enough), and retry the operation. If that
    succeeds, then this might be the issue you're hitting.

    -- David
    David Bolen, Mar 1, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John J Lee
    Replies:
    3
    Views:
    454
    bruno at modulix
    Dec 1, 2005
  2. Edward Loper
    Replies:
    0
    Views:
    443
    Edward Loper
    Aug 7, 2007
  3. John J Lee
    Replies:
    0
    Views:
    501
    John J Lee
    Aug 7, 2007
  4. x1
    Replies:
    0
    Views:
    359
  5. Iulian Ilea
    Replies:
    1
    Views:
    289
    pcx99
    Dec 21, 2006
Loading...

Share This Page