databio/yacman

file locks on nonexistant file

nsheff opened this issue · 1 comments

if you try to create a YacAttMap on a nonexistant file, it first says, "no such file directory"... but it creates a lock file anyway. When you then try to do it again, instead of saying no such file again, it says "waiting for lock" --- even though that file never existed...

problems:

  1. it checks for locks before checking if the file exists
  2. it creates a lock file even for non-eixstant files.

some demo code:

import yacman
yacman.YacAttMap(filepath="blah.yaml")
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-13ad53c54c1c> in <module>
----> 1 yacman.YacAttMap(filepath="blah.yaml")

~/.local/lib/python3.8/site-packages/yacman/yacman.py in __init__(self, entries, filepath, yamldata, writable, wait_max, skip_read_lock)
     75             if not skip_read_lock and not writable:
     76                 create_lock(filepath, wait_max)
---> 77                 file_contents = load_yaml(filepath)
     78                 remove_lock(filepath)
     79             else:

~/.local/lib/python3.8/site-packages/yacman/yacman.py in load_yaml(filepath)
    296         return yaml.safe_load(text)
    297     else:
--> 298         return read_yaml_file(filepath)
    299 
    300 

~/.local/lib/python3.8/site-packages/yacman/yacman.py in read_yaml_file(filepath)
    276         :return dict: read data
    277         """
--> 278         with open(filepath, 'r') as f:
    279             data = yaml.safe_load(f)
    280         return data

FileNotFoundError: [Errno 2] No such file or directory: 'blah.yaml'

In [4]: yacman.YacAttMap(filepath="blah.yaml")
Waiting for file lock: lock.blah.yaml .......^C---------------------------------------------------------------------------

expected behavior

if the file doesn't exist, it should just report that. no locks necessary. definitely the lock should not just stay there.

resolved on dev