Skip to content

Commit

Permalink
Merge pull request #8 from zopefoundation/fix-interaction-w-multiproc…
Browse files Browse the repository at this point in the history
…essing

Fixed: unlocking and locking didn't work when a multiprocessing
  • Loading branch information
jimfulton committed Jun 19, 2016
2 parents 8e8068f + 0fdfb09 commit c2becac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,9 @@
Change History
***************

- Fixed: unlocking and locking didn't work when a multiprocessing
process was running (and presumably other conditions).

1.2.0 (2016-06-09)
==================

Expand Down
4 changes: 1 addition & 3 deletions src/zc/lockfile/__init__.py
Expand Up @@ -59,9 +59,7 @@ def _lock_file(file):
raise LockError("Couldn't lock %r" % file.name)

def _unlock_file(file):
# File is automatically unlocked on close
pass

fcntl.flock(file.fileno(), fcntl.LOCK_UN)

class LazyHostName(object):
"""Avoid importing socket and calling gethostname() unnecessarily"""
Expand Down
18 changes: 18 additions & 0 deletions src/zc/lockfile/tests.py
Expand Up @@ -185,6 +185,24 @@ def lock(locked, before_closing):
'f.lock', '123/myhostname', '')]
assert test_logger.log_entries == expected, test_logger.log_entries

def test_unlock_and_lock_while_multiprocessing_process_running(self):
import multiprocessing

lock = zc.lockfile.LockFile('l')
q = multiprocessing.Queue()
p = multiprocessing.Process(target=q.get)
p.daemon = True
p.start()

# release and re-acquire should work (obviously)
lock.close()
lock = zc.lockfile.LockFile('l')
self.assertTrue(p.is_alive())

q.put(0)
lock.close()
p.join()


def test_suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit c2becac

Please sign in to comment.