oslo.concurrency lock file

asked 2018-06-14 01:49:28 -0500

Hi,

I wanted to use filelock, but I was told that I should use oslo.concurrency.

I have two processes and I want them to work of files. There are problems, if two or more processes work on the same file. Therefore I need that a process locks the file, so no other can work on it as well.

I tried the following:

  lockutils.lock('filename1', external=True)                                            
  print("I've got the lock")                                                      
  time.sleep(5)                                                                   
  print('Gonna free it up')

If I run two processes of this program one after another, the both print I've got the lock and then after 5 second both write Gonna free it up and exit.

I also tried external_lock but with the same result. Am I doing something wrongly, or did I not understand the lock properly?

Thank you

edit retag flag offensive close merge delete