Skip to content

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/locks/my_lock.lock' #176

Closed
@connormason

Description

@connormason

I have been intermittently seeing this error (was thinking possibly due to a race condition), but one of my coworkers started running into this issue repeatedly. Any idea why this could be happening? Reproducing solely on macOS

Code I'm running:

lock_path = '/tmp/locks/my_lock.lock'
with FileLock(lock_path, timeout=0):
   ... 

I see that in _acquire() the os.O_CREAT flag is being provided to os.open(), so shouldn't the file be created if it does not exist?

Sanitized traceback:

Traceback (most recent call last):
  File "/Users/my_user/.virtualenvs/my_proj/my_proj/cache.py", line 311, in update_cache
    with FileLock(lock_path, timeout=0):
  File "/Users/my_user/.virtualenvs/my_env/lib/python3.10/site-packages/filelock/_api.py", line 220, in __enter__
    self.acquire()
  File "/Users/my_user/.virtualenvs/my_env/lib/python3.10/site-packages/filelock/_api.py", line 173, in acquire
    self._acquire()
  File "/Users/my_user/.virtualenvs/my_env/lib/python3.10/site-packages/filelock/_unix.py", line 35, in _acquire
    fd = os.open(self._lock_file, open_mode)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/locks/my_lock.lock'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions