def it_fails_when_there_are_locks(self, tmpdir): lockfile = tmpdir.ensure('lock') lock = lockfile.open() with ShouldRaise(LockHeld): show_runaway_processes(lockfile.strpath) lock.close() show_runaway_processes(lockfile.strpath)
def clean_service(service_path): # we use SIGTERM; SIGKILL is cheating. limit = 100 while limit > 0: # pragma: no branch: we don't expect to ever hit the limit assert os.path.isdir(service_path), service_path try: show_runaway_processes(service_path) print('lock released -- done.') break except LockHeld: print('lock held -- killing!') for pid in fuser(service_path): try: os.system('ps -fj %i' % pid) os.kill(pid, signal.SIGTERM) except OSError as error: # race condition -- process stopped between list and kill :pragma: no-cover if error.errno == 3: # no such process pass else: raise limit -= 1
def it_passes_when_there_are_no_locks(self, tmpdir): assert show_runaway_processes(tmpdir.strpath) is None