Lock file without blocking Ruby process during crashes

Hello, I'm trying to lock a file using file.flock(File::LOOK_EX)

The problem is blocking the application if it cannot lock the file.

rescue doesn't help either.

Is there a way to report flock an error if it cannot lock the file on the first try?

+4
source share
1 answer

You can add the constant LOCK_NB :

 file.flock(File::LOOK_EX | File::LOCK_NB) 

This will prevent the operation from being blocked.

+4
source

Source: https://habr.com/ru/post/1443008/


All Articles