def clean_service(service_path): # we use SIGTERM; SIGKILL is cheating. print('killing.') limit = 100 while limit > 0: # pragma: no cover: we don't expect to ever hit the limit try: check_lock(service_path) break except LockHeld: for pid in lsof(service_path): try: os.kill(pid, 10) except OSError as error: if error.errno == 3: # no such process pass else: raise limit -= 1
def it_passes_when_there_are_no_locks(self, tmpdir): assert check_lock(tmpdir.strpath) is None
def it_fails_when_there_are_locks(self, tmpdir): with tmpdir.as_cwd(): with ShouldRaise(LockHeld): check_lock(tmpdir.strpath)