Example #1
0
 def test_pidfile_lock_2(self):
     lock_name = get_temp_file_name("test-2.pid")
     self.assertTrue(acquire_pidfile_lock(lock_name))
     result = examine_pidfile_lock(lock_name)
     self.assertFalse(result is None)
     (current_pid, is_running) = result
     self.assertEqual(is_running, True)
     self.assertEqual(current_pid, os.getpid())
     release_pidfile_lock(lock_name)
     result = examine_pidfile_lock(lock_name)
     self.assertEqual(result, None)
Example #2
0
def check_pidfile(path, unlink=True):
    """
    *Deprecated* as of netsa-python v1.4.  Use
    :func:`netsa.files.acquire_pidfile_lock` instead.

    Attempts to create a locking PID file at the requested pathname
    *path*.  If the file does not exist, creates it with the current
    process ID, and sets up an :mod:`atexit` process to remove it.  If
    the file does exist but refers to a no-longer-existing process,
    replaces it and does the above.  If the file does exist and refers
    to a running process, does nothing.

    Returns ``True`` if the PID file was created or replaced (which
    means we should continue processing), or ``False`` if the PID file
    was left in place (which means someone else is processing and we
    should exit.)
    """
    warnings.warn("netsa.tools.service.check_pidfile is deprecated, "
                  "please see netsa.files.acquire_pidfile_lock",
                  DeprecationWarning)
    return acquire_pidfile_lock(path)