How to use the libensemble.comms.comms.Timeout function in libensemble

To help you get started, we’ve selected a few libensemble examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Libensemble / libensemble / libensemble / comms / mpi.py View on Github external
def recv(self, timeout=None):
        "Receive a message or raise TimeoutError."
        if self._pushed is not None:
            result = self._pushed
            self._pushed = None
            return result
        if timeout is not None:
            tfinal = time.time() + timeout
            while not self.mail_flag():
                if time.time() > tfinal:
                    raise Timeout()
        result = self.mpi_comm.recv(source=self.remote_rank, status=self.status)
        return self.process_incoming(result, self.status)
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def terminate(self, timeout=None):
        "Terminate the process."
        if self.running:
            self.process.terminate()
        self.process.join(timeout=timeout)
        if self.running:
            raise Timeout()
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def result(self, timeout=None):
        "Get the result of the simulation or throw a timeout."
        while not self.done():
            if timeout is not None and timeout < 0:
                raise Timeout()
            tstart = time()
            try:
                self._ceval.process_message(timeout)
            except Timeout:
                pass
            if timeout is not None:
                timeout -= (time() - tstart)
        return self._result
github Libensemble / libensemble / libensemble / libE.py View on Github external
def kill_proc_team(wcomms, timeout):
    "Join on workers (and terminate forcefully if needed)."
    for wcomm in wcomms:
        try:
            wcomm.result(timeout=timeout)
        except Timeout:
            wcomm.terminate()
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def recv(self, timeout=None):
        "Return a message from the thread or raise TimeoutError."
        try:
            if self._done:
                raise CommFinishedException()
            if not self.outbox.empty():
                msg = self.outbox.get()
            else:
                msg = self.outbox.get(timeout=timeout)
            if self._is_result_msg(msg):
                raise CommFinishedException()
            return msg
        except queue.Empty:
            raise Timeout()
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def result(self, timeout=None):
        "Join and return the thread main result (or re-raise an exception)."
        get_timeout = _timeout_fun(timeout)
        while not self._done and (timeout is None or timeout >= 0):
            try:
                msg = self.outbox.get(timeout=timeout)
            except queue.Empty:
                raise Timeout()
            self._is_result_msg(msg)
            timeout = get_timeout()
        if not self._done:
            raise Timeout()
        self.process.terminate()
        self.process.join(timeout=timeout)
        if self.running:
            raise Timeout()
        if self._exception is not None:
            raise RemoteException(self._exception.msg, self._exception.exc)
        return self._result
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def terminate(self, timeout=None):
        "Terminate the process."
        if self.running:
            self.process.terminate()
        self.process.join(timeout=timeout)
        if self.running:
            raise Timeout()
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def recv(self, timeout=None):
        "Return a message from the inbox queue or raise TimeoutError."
        pb_result = self.recv_buffer
        self.recv_buffer = None
        if pb_result is not None:
            return pb_result
        try:
            if not self._inbox.empty():
                return self._inbox.get()
            return self._inbox.get(timeout=timeout)
        except queue.Empty:
            raise Timeout()
github Libensemble / libensemble / libensemble / libE.py View on Github external
def kill_proc_team(wcomms, timeout):
    "Join on workers (and terminate forcefully if needed)."
    for wcomm in wcomms:
        try:
            wcomm.result(timeout=timeout)
        except Timeout:
            wcomm.terminate()
github Libensemble / libensemble / libensemble / comms / comms.py View on Github external
def result(self, timeout=None):
        "Get the result of the simulation or throw a timeout."
        while not self.done():
            if timeout is not None and timeout < 0:
                raise Timeout()
            tstart = time()
            try:
                self._ceval.process_message(timeout)
            except Timeout:
                pass
            if timeout is not None:
                timeout -= (time() - tstart)
        return self._result