Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > cannot open file in write mode, no such file or directory

Reply
Thread Tools

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

 
 
haynesc@gmail.com
Guest
Posts: n/a
 
      02-28-2005
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

 
Reply With Quote
 
 
 
 
Kartic
Guest
Posts: n/a
 
      02-28-2005
> 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

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      02-28-2005
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

 
Reply With Quote
 
haynesc@gmail.com
Guest
Posts: n/a
 
      02-28-2005
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.

 
Reply With Quote
 
Kartic
Guest
Posts: n/a
 
      02-28-2005
Could you please post your entire program, if possible?

Thanks!

 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      02-28-2005

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
David Bolen
Guest
Posts: n/a
 
      03-01-2005
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python make dies :libtk8.5.so: cannot open shared object file: Nosuch file or directory Tony Lay Python 1 07-13-2009 02:24 PM
is better to open, write, close file than open, write, append, close? Iulian Ilea Javascript 1 12-21-2006 04:32 PM
Error Installing 'termios' [ld: fatal: file crt1.o: open failed: No such file or directory] x1 Ruby 0 10-30-2005 06:50 AM
The file 'bin\WebProj.dll' cannot be copied to the run directory. The requested operation cannot be performed on a file with a user-mapped section open. J Gao ASP .Net 0 07-28-2003 04:18 PM



Advertisments