How to use the poap.tcpserve.SocketWorker function in POAP

To help you get started, we’ve selected a few POAP 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 dbindel / POAP / poap / tcpserve.py View on Github external
request for the record.  If, on the other hand, there is a
        problem with calling send, we probably want to let the worker
        error out.

        Args:
            record_id: Feval record identifier used by server/controller
            params: Parameters sent to the function to be evaluated
        """
        try:
            msg = ('complete', record_id, self.objective(*params))
        except:
            msg = ('cancel', record_id)
        self.send(*msg)


class ProcessSocketWorker(SocketWorker):
    """Socket worker that runs an evaluation in a subprocess

    The ProcessSocketWorker is a base class for simulations that run a
    simulation in an external subprocess.  This class provides functionality
    just to allow graceful termination of the external simulations.

    Attributes:
        process: Handle for external subprocess
    """

    def __init__(self, sockname, retries=0):
        """Initialize the ProcessSocketWorker.

        The constructor tries to open the socket; on failure, it keeps
        trying up to retries times, once per second.
github dbindel / POAP / poap / tcpserve.py View on Github external
"Terminate the worker"
        self.running = False

    def run(self, loop=True):
        "Main loop"
        try:
            self._run()
            while loop and self.running:
                self._run()
        except socket.error as e:
            logger.warning("Exit loop: {0}".format(e))
        finally:
            self.sock.close()


class SimpleSocketWorker(SocketWorker):
    """Simple socket worker that runs a local objective function

    The SimpleSocketWorker is a socket worker that runs a local Python
    function and returns the result.  It is probably mostly useful for
    testing -- the ProcessSocketWorker is a better option for external
    simulations.
    """

    def __init__(self, objective, sockname, retries=0):
        """Initialize the SimpleSocketWorker.

        The constructor tries to open the socket; on failure, it keeps
        trying up to retries times, once per second.

        Args:
            objective: Python objective function