def start(self):
        if not os.path.exists(self.proxyBinPath):
            return None
        # We will start the proxy on these ports
        self.port, self.authPort = testhelp.findPorts(num = 2)

        self.writeConfigFile()

        stdout = open(os.devnull, "w+")
        stderr = open(os.devnull, "w+")
        # For debugging squid, uncomment the next line
        #stderr = None

        # Kill any existing proxies first
        p = subprocess.Popen(self.getStopCmd(), stdout=stderr, stderr=stderr)
        ret = p.wait()

        # Initialize cache
        p = subprocess.Popen(self.getInitCmd(), stdout=stderr, stderr=stderr)
        ret = p.wait()
        if ret != 0:
            raise Exception("Unable to init squid with config file %s: %s" %
                (self.configFile, ret))

        # Start it
        p = subprocess.Popen(self.getStartCmd(), stdout=stderr, stderr=stderr)
        ret = p.wait()
        if ret != 0:
            raise Exception("Unable to start squid with config file %s: %s" %
                (self.configFile, ret))

        # Wait till we can open a connection
        sock_utils.tryConnect("127.0.0.1", self.port)

        # Save the pid, in case the directory gets removed
        # Loop several times if squid didn't have the chance to write the pid
        # file
        for i in range(10):
            if os.path.exists(self.pidFile):
                break
            time.sleep(0.1)
        else:
            # Give it several more seconds before failing
            time.sleep(2)
        self.pid = int(open(self.pidFile).readline().strip())

        self.stopped = False
        proxyUri = "127.0.0.1:%s" % self.port
        return proxyUri
dataset/ETHPy150Open sassoftware/conary/conary_test/rephelp.py/HTTPProxy.start/original