Beispiel #1
0
    def __start_process(self, db_name, options, wait_seconds):
        """
        @type db_name str
        @type options list[tuple[str]]
        @type wait_seconds int
        @rtype: Process | None
        """
        if wait_seconds is None:
            startProcess(self.connect_str, self.__domain.user, self.__domain.password, db_name, options)
            return

        e = Event()
        # acquire the lock to avoid _notify_start_id reading the __start_id_slots map before we put the event inside it
        self.__lock.acquire()
        try:
            start_response = startProcess(
                self.connect_str, self.__domain.user, self.__domain.password, db_name, options
            )

            start_id = ElementTree.fromstring(start_response).get("StartId")
            if not start_id:
                return

            self.__start_id_slots[start_id] = e
        finally:
            self.__lock.release()

        if wait_seconds == 0:
            e.wait()
        else:
            e.wait(wait_seconds)

        if not e.isSet():
            del self.__start_id_slots[start_id]
            raise SessionException("Timed out waiting for process start")

        result = self.__start_id_slots[start_id]
        del self.__start_id_slots[start_id]

        # if the process failed to start in some known way then what's in the
        # "slot"  will be some meaningful error message, not a process instance
        if not isinstance(result, Process):
            raise SessionException(str(result))

        return result
Beispiel #2
0
    def __start_process(self, db_name, options, wait_seconds):
        """
        @type db_name str
        @type options list[tuple[str]]
        @type wait_seconds int
        @rtype: Process | None
        """
        if wait_seconds is None:
            startProcess(self.connect_str, self.__domain.user, self.__domain.password, db_name, options)
            return

        e = Event()
        # acquire the lock to avoid _notify_start_id reading the __start_id_slots map before we put the event inside it
        self.__lock.acquire()
        try:
            start_response = startProcess(self.connect_str, self.__domain.user, self.__domain.password, db_name, options)

            start_id = ElementTree.fromstring(start_response).get("StartId")
            if not start_id:
                return

            self.__start_id_slots[start_id] = e
        finally:
            self.__lock.release()

        if wait_seconds == 0:
            e.wait()
        else:
            e.wait(wait_seconds)

        if not e.isSet():
            del self.__start_id_slots[start_id]
            raise SessionException("Timed out waiting for process start")

        result = self.__start_id_slots[start_id]
        del self.__start_id_slots[start_id]

        # if the process failed to start in some known way then what's in the
        # "slot"  will be some meaningful error message, not a process instance
        if not isinstance(result, Process):
            raise SessionException(str(result))

        return result
Beispiel #3
0
    def __startProcess(self, db_name, options, waitSeconds):
        if waitSeconds == None:
            startProcess(self.getConnectStr(), self.__domain.getUser(), self.__domain.getPassword(), db_name, options)
            return

        e = Event()
        # acquire the lock to avoid _notifyStartId reading the __startIdSlots map before we put the event inside it
        self.__lock.acquire()
        try:
            startResponse = startProcess(
                self.getConnectStr(), self.__domain.getUser(), self.__domain.getPassword(), db_name, options
            )

            startId = ElementTree.fromstring(startResponse).get("StartId")
            if not startId:
                return

            self.__startIdSlots[startId] = e
        finally:
            self.__lock.release()

        if waitSeconds == 0:
            e.wait()
        else:
            e.wait(waitSeconds)

        if not e.isSet():
            del self.__startIdSlots[startId]
            raise SessionException("Timed out waiting for process start")

        result = self.__startIdSlots[startId]
        del self.__startIdSlots[startId]

        # if the process failed to start in some known way then what's in the
        # "slot"  will be some meaningful error message, not a process instance
        if not isinstance(result, Process):
            raise SessionException(str(result))

        return result