Esempio n. 1
0
 def test_processCmdline(self):
     pid = self.createProcess()
     self.assertRegex(tools.processCmdline(pid),
                      r'.*/sh.*/common/test/dummy_test_process\.sh')
     self.killProcess()
     pid = self.createProcess('foo', 'bar')
     self.assertRegex(tools.processCmdline(pid),
                      r'.*/sh.*/common/test/dummy_test_process\.sh.foo.bar')
Esempio n. 2
0
 def test_processCmdline(self):
     pid = self.createProcess()
     self.assertRegex(tools.processCmdline(pid),
                      r'.*/sh.*/common/test/dummy_test_process\.sh')
     self.killProcess()
     pid = self.createProcess('foo', 'bar')
     self.assertRegex(tools.processCmdline(pid),
                      r'.*/sh.*/common/test/dummy_test_process\.sh.foo.bar')
Esempio n. 3
0
    def test_existing_process_with_correct_proc_cmdline(self):
        """
        Test the check function with an existing process with correct process
        cmdline (for backwards compatibility)
        """
        pid = self.createProcess()
        procname = tools.processCmdline(pid)

        # create file with pid and process name
        with open(self.file_name, "wt") as file_with_pid:
            file_with_pid.write(str(pid) + "\n")
            file_with_pid.write(procname)

        # Execute test
        self.assertFalse(self.inst.check())
    def check(self, autoExit=False):
        """
        Check if the current application is already running

        Args:
            autoExit (bool):   automatically call sys.exit if there is an other
                                instance running

        Returns:
            bool:               ``True`` if this is the only application
                                instance
        """
        #check if the pidfile exists
        if not os.path.isfile(self.pidFile):
            return True

        self.pid, self.procname = self.readPidFile()

        #check if the process with specified by pid exists
        if 0 == self.pid:
            return True

        if not tools.processAlive(self.pid):
            return True

        #check if the process has the same procname
        #check cmdline for backwards compatibility
        if self.procname and                                    \
           self.procname != tools.processName(self.pid) and    \
           self.procname != tools.processCmdline(self.pid):
            return True

        if autoExit:
            #exit the application
            print("The application is already running !")
            exit(
                0
            )  #exit raise an exception so don't put it in a try/except block

        return False
Esempio n. 5
0
    def check(self, autoExit = False):
        """
        Check if the current application is already running

        Args:
            autoExit (bool):   automatically call sys.exit if there is an other
                                instance running

        Returns:
            bool:               ``True`` if this is the only application
                                instance
        """
        #check if the pidfile exists
        if not os.path.isfile(self.pidFile):
            return True

        self.pid, self.procname = self.readPidFile()

        #check if the process with specified by pid exists
        if 0 == self.pid:
            return True

        if not tools.processAlive(self.pid):
            return True

        #check if the process has the same procname
        #check cmdline for backwards compatibility
        if self.procname and                                    \
           self.procname != tools.processName(self.pid) and    \
           self.procname != tools.processCmdline(self.pid):
                return True

        if autoExit:
            #exit the application
            print("The application is already running !")
            exit(0) #exit raise an exception so don't put it in a try/except block

        return False
Esempio n. 6
0
 def test_processCmdline_exception(self, mock_open):
     mock_open.side_effect = OSError()
     pid = self.createProcess()
     self.assertEqual(tools.processCmdline(pid), '')
Esempio n. 7
0
 def test_processCmdline_exception(self, mock_open):
     mock_open.side_effect = OSError()
     pid = self.createProcess()
     self.assertEqual(tools.processCmdline(pid), '')