Exemplo n.º 1
0
def main():
    with kiwipy.connect(
            'amqp://127.0.0.1') as communicator, tempfile.TemporaryDirectory(
            ) as tmpdir:
        loop = asyncio.get_event_loop()
        persister = plumpy.PicklePersister(tmpdir)
        task_receiver = plumpy.ProcessLauncher(loop=loop, persister=persister)

        def callback(*args, **kwargs):
            fut = plumpy.create_task(functools.partial(task_receiver, *args,
                                                       **kwargs),
                                     loop=loop)
            return fut

        communicator.add_task_subscriber(callback)

        process_controller = plumpy.RemoteProcessThreadController(communicator)

        future = process_controller.launch_process(DummyProcessWithOutput)

        async def task():
            result = await asyncio.wrap_future(future.result())
            print(result)

        loop.run_until_complete(task())
Exemplo n.º 2
0
def launch():
    message_exchange = '{}.{}'.format('WaitForResume', 'uuid-0')
    task_exchange = '{}.{}'.format('WaitForResume', 'uuid-0')
    task_queue = '{}.{}'.format('WaitForResume', 'uuid-0')

    kwargs = {
        'connection_params': {
            'url': 'amqp://*****:*****@127.0.0.1:5672/'
        },
        'message_exchange': message_exchange,
        'task_exchange': task_exchange,
        'task_queue': task_queue,
    }
    try:
        with rmq.RmqThreadCommunicator.connect(**kwargs) as communicator:
            proc = WaitForResumeProc(communicator=communicator)
            process_controller = plumpy.RemoteProcessThreadController(
                communicator)

            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: False

            process_controller.pause_process(proc.pid)
            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: True

            process_controller.play_process(proc.pid)
            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: False

    except KeyboardInterrupt:
        pass
Exemplo n.º 3
0
    def __init__(self, poll_interval=0, loop=None, communicator=None, rmq_submit=False, persister=None):
        """
        Construct a new runner

        :param poll_interval: interval in seconds between polling for status of active calculations
        :param loop: an event loop to use, if none is suppled a new one will be created
        :type loop: :class:`tornado.ioloop.IOLoop`
        :param communicator: the communicator to use
        :type communicator: :class:`kiwipy.Communicator`
        :param rmq_submit: if True, processes will be submitted to RabbitMQ, otherwise they will be scheduled here
        :param persister: the persister to use to persist processes
        :type persister: :class:`plumpy.Persister`
        """
        assert not (rmq_submit and persister is None), \
            'Must supply a persister if you want to submit using communicator'

        self._loop = loop if loop is not None else tornado.ioloop.IOLoop()
        self._poll_interval = poll_interval
        self._rmq_submit = rmq_submit
        self._transport = transports.TransportQueue(self._loop)
        self._job_manager = manager.JobManager(self._transport)
        self._persister = persister
        self._plugin_version_provider = PluginVersionProvider()

        if communicator is not None:
            self._communicator = communicator
            self._controller = plumpy.RemoteProcessThreadController(communicator)
        elif self._rmq_submit:
            LOGGER.warning('Disabling RabbitMQ submission, no communicator provided')
            self._rmq_submit = False
Exemplo n.º 4
0
    def get_process_controller(self):
        """Return the process controller

        :return: the process controller instance
        :rtype: :class:`plumpy.RemoteProcessThreadController`
        """
        import plumpy
        if self._process_controller is None:
            self._process_controller = plumpy.RemoteProcessThreadController(self.get_communicator())

        return self._process_controller
Exemplo n.º 5
0
    message_exchange = "{}.{}".format("WaitForResume", "uuid-0")
    task_exchange = "{}.{}".format("WaitForResume", "uuid-0")
    task_queue = "{}.{}".format("WaitForResume", "uuid-0")

    kwargs = {
        'connection_params': {
            'url': 'amqp://*****:*****@127.0.0.1:5672/'
        },
        'message_exchange': message_exchange,
        'task_exchange': task_exchange,
        'task_queue': task_queue,
    }
    try:
        with rmq.RmqThreadCommunicator.connect(**kwargs) as communicator:
            proc = WaitForResumeProc(communicator=communicator)
            process_controller = plumpy.RemoteProcessThreadController(
                communicator)

            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: False

            process_controller.pause_process(proc.pid)
            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: True

            process_controller.play_process(proc.pid)
            status_future = process_controller.get_status(proc.pid)
            print(status_future.result())  # pause: False

    except KeyboardInterrupt:
        pass