3

I have a program that - on startup - checks to see if the user-supplied output directory exists. If the directory can not be found the program attempts to create it:

if not os.path.exists(path):
  os.makedirs(path)

Path is a standard absolute path to a directory such as '/mnt/share/path/to/output'

It works about 75% of the time. The rest of the time I get either "exception.OSError," or "exception.IOError: [Errno 2] No such file or directory." Both exceptions have the same error number and text.

Why is this happening? I don't see how it would be permissions related or anything like that - I am writing as myself to directories I own and control - and again it works the other 3 out of 4 times. I am writing the same directory to the same place every time and deleting it recursively between program invocations for testing. It is writing to a remote share (NFS) if that matters at all.

James Mishra
  • 4,249
  • 4
  • 30
  • 35
jayce
  • 293
  • 2
  • 9

1 Answers1

0

I guess this is an issue of a Race Condition take a look at this answer Race Condition, Hope it helps.

Nash
  • 105
  • 1
  • 9
  • How is it an example of a race condition? Nothing is competing to access or create this directory tree. By the time the program executes, the directory has already been removed. – jayce Mar 08 '18 at 16:01
  • Read these two answer maybe it'll clear things up for you. https://stackoverflow.com/questions/29347790/difference-between-ioerror-and-oserror https://stackoverflow.com/questions/18973418/os-mkdirpath-returns-oserror-when-directory-does-not-exist – Nash Mar 13 '18 at 20:25