コード例 #1
0
def main(cmds):
    
    previous_master_state = None
    while True:
        master_state = isMasterAlive()
        if not master_state:
            print "Master is dead..."
        if not master_state and previous_master_state:
            print "kill process"    
            killProcess()
        elif master_state and not previous_master_state:
            print "restart process"
            runProcess(cmds)
        previous_master_state = master_state
        time.sleep(1.0)
コード例 #2
0
def main(cmds):

    previous_master_state = None
    while True:
        master_state = isMasterAlive()
        if not master_state:
            print "Master is dead..."
        if not master_state and previous_master_state:
            print "kill process"
            killProcess()
        elif master_state and not previous_master_state:
            print "restart process"
            runProcess(cmds)
        previous_master_state = master_state
        time.sleep(1.0)
コード例 #3
0
def main(topics, size, save_dir, max_size, rate = 1):
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    previous_master_state = None
    try:
        while True:
            master_state = isMasterAlive()
            if not master_state and previous_master_state:
                print "kill rosbag"
                killROSBag()
            elif master_state and not previous_master_state:
                print "restart rosbag"
                restartROSBag(topics, size, save_dir)
            watchFileSystem(save_dir, max_size)
            previous_master_state = master_state
            time.sleep(1.0 / rate)
    except Exception, e:
        time.sleep(1)
        watchFileSystem(save_dir, max_size)
コード例 #4
0
def main(topics, size, save_dir, max_size, rate=1):
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    previous_master_state = None
    try:
        while True:
            master_state = isMasterAlive()
            if not master_state and previous_master_state:
                print "kill rosbag"
                killROSBag()
            elif master_state and not previous_master_state:
                print "restart rosbag"
                restartROSBag(topics, size, save_dir)
            watchFileSystem(save_dir, max_size)
            previous_master_state = master_state
            time.sleep(1.0 / rate)
    except Exception, e:
        time.sleep(1)
        watchFileSystem(save_dir, max_size)
コード例 #5
0
def main(args):
    cmds, respawn, timeout, sigint_timeout, sigterm_timeout, trials = parse_args(
        args)
    exit_code = 0
    previous_master_state = None
    try:
        while True:
            master_state = isMasterAlive(timeout_sec=timeout, trials=trials)
            if g_process_object and g_process_object.poll() is not None:
                # Child process exited
                pid = g_process_object.pid
                exit_code = g_process_object.poll()
                printLog("Child process exited [%d] (code: %d)" %
                         (pid, exit_code))
                if respawn:
                    printLog("Restarting process")
                    runProcess(cmds)
                    printLog("Process restarted [%d]" % g_process_object.pid)
                else:
                    break
            if not master_state and previous_master_state:
                # Master is gone dead
                pid = g_process_object.pid
                printLog("Killing running process")
                exit_code = killProcess(sigint_timeout, sigterm_timeout)
                printLog("Killed running process [%d] (code: %d)" %
                         (pid, exit_code))
            elif master_state and not previous_master_state:
                # Master is now alive
                printLog("Starting process")
                runProcess(cmds)
                printLog("Process started [%d]" % g_process_object.pid)
            previous_master_state = master_state
            time.sleep(1.0)
    except KeyboardInterrupt:
        pass
    finally:
        printLog("Cleaning up processes")
        exit_code = killProcess(sigint_timeout, sigterm_timeout)

    return exit_code
コード例 #6
0
def main(args):
    cmds, respawn = parse_args(args)
    exit_code = 0
    previous_master_state = None
    try:
        while True:
            master_state = isMasterAlive()
            if g_process_object and g_process_object.poll() is not None:
                # Child process exited
                pid = g_process_object.pid
                exit_code = g_process_object.poll()
                printLog("Child process exited [%d] (code: %d)" % (pid, exit_code))
                if respawn:
                    printLog("Restarting process")
                    runProcess(cmds)
                    printLog("Process restarted [%d]" % g_process_object.pid)
                else:
                    break
            if not master_state and previous_master_state:
                # Master is gone dead
                pid = g_process_object.pid
                printLog("Killing running process")
                exit_code = killProcess()
                printLog("Killed running process [%d] (code: %d)" % (pid, exit_code))
            elif master_state and not previous_master_state:
                # Master is now alive
                printLog("Starting process")
                runProcess(cmds)
                printLog("Process started [%d]" % g_process_object.pid)
            previous_master_state = master_state
            time.sleep(1.0)
    except KeyboardInterrupt:
        pass
    finally:
        printLog("Cleaning up processes")
        exit_code = killProcess()

    return exit_code
コード例 #7
0
def check_master():
    return isMasterAlive()
コード例 #8
0
 def test_isMasterAlive(self):
     self.assertTrue(isMasterAlive())
     self.assertTrue(isMasterAlive(10, 1))
     os.environ["ROS_MASTER_URI"] = 'http://baduri:11311'
     self.assertFalse(isMasterAlive())
     self.assertFalse(isMasterAlive(10, 1))