Esempio n. 1
0
 def test_lock_multiple(self):
     # Lock + unlock a lock multiple times.
     fname = self.tempname()
     lock = platform.lock_file(fname)
     platform.unlock_file(lock)
     lock = platform.lock_file(fname)
     platform.unlock_file(lock)
Esempio n. 2
0
 def close(self):
     """Close the store file, and unlock it if it was locked."""
     if self._connection is None:
         return
     self._connection.close()
     self._connection = None
     if self._lock:
         platform.unlock_file(self._lock)
         self._lock = None
     self._filename = None
Esempio n. 3
0
 def test_lock_multiple(self):
     fname = self.tempfile()
     lock = lock_file(fname)
     # The tests below would require flock() on Posix which does per-fd
     # locking instead of lockf() which is per process. However flock() is
     # not safe on NFS on all platforms. So disable these tests.
     #err = assert_raises(LockError, lock_file, fname)
     #assert hasattr(err, 'lock_pid')
     #assert err.lock_pid == os.getpid()
     #assert hasattr(err, 'lock_uid')
     #assert err.lock_uid == os.getuid()
     #assert hasattr(err, 'lock_cmd')
     #assert sys.argv[0].endswith(err.lock_cmd)
     unlock_file(lock)
     lock = lock_file(fname)
     unlock_file(lock)
Esempio n. 4
0
 def test_lock_locked_unix(self):
     # Lock a lock that is already locked. This should raise an OSError.
     fname = self.tempname()
     pid = os.fork()
     # The locks are per process. So need to fork here.
     if pid == 0:
         # child
         lock = platform.lock_file(fname)
         try:
             time.sleep(1)
         except KeyboardInterrupt:
             pass
         platform.unlock_file(lock)
         os._exit(0)
     time.sleep(0.1)
     self.assertRaises(OSError, platform.lock_file, fname)
     # Exit the child now, which will release the lock
     os.kill(pid, signal.SIGINT)
     os.waitpid(pid, 0)
     lock = platform.lock_file(fname)
     platform.unlock_file(lock)
Esempio n. 5
0
 def test_lock_unlock(self):
     fname = self.tempfile()
     lock = lock_file(fname)
     unlock_file(lock)
Esempio n. 6
0
 def unlock(self):
     """Unlock the database."""
     if not self._lock:
         return
     platform.unlock_file(self._lock)
     self._lock = None
Esempio n. 7
0
 def test_lock_basic(self):
     # Ensure that a basic lock + unlock works.
     fname = self.tempname()
     lock = platform.lock_file(fname)
     platform.unlock_file(lock)