How to use the simgrid.Mailbox function in simgrid

To help you get started, we’ve selected a few simgrid 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 simgrid / simgrid / examples / python / actor-create / actor-create.py View on Github external
def receiver(mailbox_name):
    """
    Our first class of actors is simply implemented with a function, that takes a single string as parameter.
    Later, this actor class is instantiated within the simulation.
    """
    mailbox = Mailbox.by_name(mailbox_name)

    this_actor.info(
        "Hello s4u, I'm ready to get any message you'd want on {:s}".format(mailbox.name))

    msg1 = mailbox.get()
    msg2 = mailbox.get()
    msg3 = mailbox.get()
    this_actor.info(
        "I received '{:s}', '{:s}' and '{:s}'".format(msg1, msg2, msg3))
    this_actor.info("I'm done. See you.")
github simgrid / simgrid / examples / python / async-wait / async-wait.py View on Github external
def __call__(self):
        # FIXME: It should be ok to initialize self.mbox from __init__, but it's currently failing on the OS X Jenkins slave.
        self.mbox = Mailbox.by_name("receiver-{:d}".format(self.id))
        this_actor.info("Wait for my first message")
        while True:
            received = self.mbox.get()
            this_actor.info("I got a '{:s}'.".format(received))
            if received == "finalize":
                break  # If it's a finalize message, we're done.
github simgrid / simgrid / examples / python / async-waitany / async-waitany.py View on Github external
def __init__(self, *args):
        if len(args) != 1:  # Receiver actor expects 1 argument: its ID
            raise AssertionError(
                "Actor receiver requires 1 parameter, but got {:d}".format(len(args)))
        self.mbox = Mailbox.by_name("receiver-{:s}".format(args[0]))
github simgrid / simgrid / examples / python / actor-create / actor-create.py View on Github external
def forwarder(*args):
    """Our second class of actors is also a function"""
    if len(args) < 2:
        raise AssertionError(
            "Actor forwarder requires 2 parameters, but got only {:d}".format(len(args)))
    mb_in = Mailbox.by_name(args[0])
    mb_out = Mailbox.by_name(args[1])

    msg = mb_in.get()
    this_actor.info("Forward '{:s}'.".format(msg))
    mb_out.put(msg, len(msg))
github simgrid / simgrid / examples / python / async-waitall / async-waitall.py View on Github external
def __init__(self, *args):
        if len(args) != 1:  # Receiver actor expects 1 argument: its ID
            raise AssertionError(
                "Actor receiver requires 1 parameter, but got {:d}".format(len(args)))
        self.mbox = Mailbox.by_name("receiver-{:s}".format(args[0]))