bug with os.rename in 2.4.1?

t123 tom.lukes at gmail.com
Tue Apr 28 19:43:01 CEST 2009


It's running on solaris 9.  Here is some of the code.  It's actually
at the beginning of the job.  The files are ftp'd over.  The first
thing that happens is that the files get renamed before any processing
of the file.  And when it fails, it always fails at the first file,
comm.dat.  What I can't understand is why the inconsistent behavior.

try:
        if os.path.exists(paths.xferin_dir+'/COMM.DAT'):
          os.rename(paths.xferin_dir+'/COMM.DAT',paths.xferin_dir+'/
COMM.DAT'+'.0')
        if os.path.exists(paths.xferin_dir+'/DESC.DAT'):
          os.rename(paths.xferin_dir+'/DESC.DAT',paths.xferin_dir+'/
DESC.DAT'+'.0')
        if os.path.exists(paths.xferin_dir+'/HEADER.DAT'):
          os.rename(paths.xferin_dir+'/HEADER.DAT',paths.xferin_dir+'/
HEADER.DAT'+'.0')
        if os.path.exists(paths.xferin_dir+'/LINE.DAT'):
          os.rename(paths.xferin_dir+'/LINE.DAT',paths.xferin_dir+'/
LINE.DAT'+'.0')

except:
    print "Unexpected error:", sys.exc_info()[0]
    raise

On Apr 28, 12:25 pm, Duncan Booth <duncan.bo... at invalid.invalid>
wrote:
> t123 <tom.lu... at gmail.com> wrote:
> > I was wondering if anyone has seen this problem before?
>
> > I have a job that runs hourly.  Part of the processing is to rename a
> > file using os.rename.  The file name is the same every hour.
> > Sometimes the os.rename fails and the file does not get renamed.  It
> > only happens occasionally.  Most of the time it works just fine.
>
> > Appreciate any ideas.
>
> My crystal ball says you are using Windows and don't always close the file
> before you try to rename it.




More information about the Python-list mailing list