Manage Rv launch with RvCommunicator


i am looking to control RV with a simple python script. 

And i wish to launch RV and create a RvCommunicator at the same time . Sush at this:

p = subprocess.Popen('rv -network -networkPort 45000', shell=True)

self.rvc = rvNetwork.RvCommunicator("AddSource");

self.rvc.connect ("", '45000')


But it doesnt work since Rv take forever to start. Is there a way to monitor the launch of RV and know when it is ready to start to connect with it ?



  • 0
    Jon Morley

    For posterity I am copying in the private reply here for others with similar questions:

    As you mention RV takes time to start, but the other problem with the above code is that it assumes that RV will be listening on the port you asked for, which is not necessarily true (RV will fall back to other port numbers if that one is occupied).

    Something like the following should be more reliable:

        # Make sure my port file doesn't exist
        try :
            os.remove (portFile)
        except :
        # Add args to RV to save port in file after startup
        args += ["-flags", "networkPortFile=/tmp/port", "-network"]
        # Start RV as sub-process
        #  Wait until port file appears, and pull port number out of it
        port = 0
        for i in range (300) :
            if (os.path.exists (portFile)) :
                f = open (portFile)
                port = int(f.read())
            else :
                time.sleep (0.1)

    In general any process at all could be listening on one of these  officially "unassigned" port numbers, and if so, RV will try another,  but whatever port it ends up listening on will be the one it writes in that file.