TST: fix multiplatform support for process lock tests

This commit is contained in:
John Tyree 2016-02-15 13:55:53 -06:00
parent 8b63aafd5a
commit 4d4b4571a5
2 changed files with 12 additions and 11 deletions

View File

@ -223,21 +223,23 @@ class _InterProcessLock(object):
class _WindowsLock(_InterProcessLock):
"""Interprocess lock implementation that works on windows systems."""
def trylock(self):
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
def trylock(self, lockfile=None):
fileno = (lockfile or self.lockfile).fileno()
msvcrt.locking(fileno, msvcrt.LK_NBLCK, 1)
def unlock(self):
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_UNLCK, 1)
def unlock(self, lockfile=None):
fileno = (lockfile or self.lockfile).fileno()
msvcrt.locking(fileno, msvcrt.LK_UNLCK, 1)
class _FcntlLock(_InterProcessLock):
"""Interprocess lock implementation that works on posix systems."""
def trylock(self):
fcntl.lockf(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
def trylock(self, lockfile=None):
fcntl.lockf(lockfile or self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
def unlock(self):
fcntl.lockf(self.lockfile, fcntl.LOCK_UN)
def unlock(self, lockfile=None):
fcntl.lockf(lockfile or self.lockfile, fcntl.LOCK_UN)
if os.name == 'nt':

View File

@ -16,7 +16,6 @@
# under the License.
import errno
import fcntl
import multiprocessing
import os
import shutil
@ -124,9 +123,9 @@ class ProcessLockTest(test.TestCase):
count = 0
for handle in handles:
try:
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
pl.InterProcessLock.trylock(handle)
count += 1
fcntl.flock(handle, fcntl.LOCK_UN)
pl.InterProcessLock.unlock(handle)
except IOError:
os._exit(2)
finally: