Shared file locks don't work between processes

Bug #1899022 reported by Gorka Eguileor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tooz
New
Undecided
Unassigned

Bug Description

Currently only the FileLock driver implements shared locks, but contrary to what one would expect, they only work within the same process and don't work between processes.

This is easy to confirm. Besides reading the code, we can just run the following code:

  import multiprocessing
  import os
  import time

  from tooz import coordination

  def test(i):
      cwd = os.getcwd()
      me = str(os.getpid())
      print(f'Starting coordinator for process {me}')
      coordinator = coordination.get_coordinator('file://' + cwd, me)
      coordinator.start(start_heart=True)
      try:
          lock = coordinator.get_lock(b'test_shared')
          with lock (blocking=True, shared=True):
              print(f'Shared lock acquired by {me}, proceeding to sleep')
              time.sleep(5)
          print(f'Shared lock released by {me}')
      finally:
          coordinator.stop()
          print(f'Stopped coordinator for process {me}')

  with multiprocessing.Pool(2) as p:
      p.map(test, range(2))

And we'll see that shared locks between processes are behaving like exclusive locks:
  Starting coordinator for process 14772
  Starting coordinator for process 14773
  Shared lock acquired by 14772, proceeding to sleep
  Shared lock released by 14772
  Stopped coordinator for process 14772
  Shared lock acquired by 14773, proceeding to sleep
  Shared lock released by 14773
  Stopped coordinator for process 14773
  [None, None]

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.