0

There is a problem in my app that I experienced today, with saving files. The strange thing is that the code should be foolproof here. This is where I get an error:

if not os.path.exists(os.path.abspath(os.path.join(file_path, os.pardir))):
        os.makedirs(os.path.abspath(os.path.join(file_path, os.pardir)))

Above returns:

OSError: [Errno 17] File exists: '/home/ubuntu/nfs/somedir' 

How could os.path.exists give another result than os.makedirs? Is it related to the code or could it be hardware? The path specified is an EBS from AWS mounted into the OS at /home/ubuntu/nfs. Also, Zabbix sent me an alert about high CPU I/O wait time for saving on disk (didn't mention which disk).

Could it be AWS storage inaccessibility or really there are conditions under which above code won't work? Hosted on Ubuntu Server.

adamczi
  • 343
  • 1
  • 7
  • 24
  • 1
    https://docs.python.org/2/library/os.path.html names a few situations where os.path.exists can return False even if actual path exists. Have you checked those, to be sure? – bipll Jan 24 '18 at 12:48
  • 1
    Moreover, https://docs.python.org/2/library/os.html#files-and-directories says: 'Note: makedirs() will become confused if the path elements to create include os.pardir.' Again, looks suspicious. – bipll Jan 24 '18 at 12:49
  • 'nfs' refers to the network filesystem? If so, the problem could be related to that. – LMC Jan 24 '18 at 12:53
  • After stopping a process that was causing excessive CPU load (which was creating files on the NFS) the problem disappeared. It looks like it may be related both to `os.pardir` inside `os.makedirs` and the storage itself. I'll try to reproduce that again. Thanks for your clues. – adamczi Jan 25 '18 at 10:21

0 Answers0