How to use the poap.controller.BaseWorkerThread 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 / controller.py View on Github external
def __init__(self, controller, objective):
        "Initialize the worker."
        super(BasicWorkerThread, self).__init__(controller)
        self.objective = objective

    def handle_eval(self, record):
        try:
            value = self.objective(*record.params)
            self.finish_success(record, value)
            logger.debug("Worker finished feval successfully")
        except Exception:
            self.finish_cancelled(record)
            logger.debug("Worker feval exited with exception")


class ProcessWorkerThread(BaseWorkerThread):
    """Subprocess worker for use with the thread controller.

    The ProcessWorkerThread is meant for use as a base class.
    Implementations that inherit from ProcessWorkerThread should
    define a handle_eval method that sets the process field so that it
    can be interrupted if needed.  This allows use of blocking
    communication primitives while at the same time allowing
    interruption.
    """

    def __init__(self, controller):
        "Initialize the worker."
        super(ProcessWorkerThread, self).__init__(controller)
        self.process = None

    def _kill_process(self):
github dbindel / POAP / poap / controller.py View on Github external
if request[0] == 'eval':
                logger.debug("Worker thread received eval request")
                record = request[1]
                self.add_message(record.running)
                self.handle_eval(record)
            elif request[0] == 'kill':
                logger.debug("Worker thread received kill request")
                self.handle_kill(request[1])
            elif request[0] == 'terminate':
                logger.debug("Worker thread received terminate request")
                self.handle_terminate()
                logger.debug("Exit worker thread run()")
                return


class BasicWorkerThread(BaseWorkerThread):
    """Basic worker for use with the thread controller.

    The BasicWorkerThread calls a Python objective function
    when asked to do an evaluation.  This is concurrent, but only
    results in parallelism if the objective function implementation
    itself allows parallelism (e.g. because it communicates with
    an external entity via a pipe, socket, or whatever).
    """

    def __init__(self, controller, objective):
        "Initialize the worker."
        super(BasicWorkerThread, self).__init__(controller)
        self.objective = objective

    def handle_eval(self, record):
        try:
github dbindel / POAP / poap / controller.py View on Github external
def __init__(self, controller):
        "Initialize the worker."
        logger.debug("Initialize worker thread")
        super(BaseWorkerThread, self).__init__()
        self.controller = controller
        self.queue = Queue.Queue()