X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1fa3f778c3669d0658cf13b6da1a5c35b452a678..8bf7ffc43ad5507982e924a7f05bbb13c89965cb:/examples/python/actor-create/actor-create.py diff --git a/examples/python/actor-create/actor-create.py b/examples/python/actor-create/actor-create.py index 3bd71d56f1..2c7f623f81 100644 --- a/examples/python/actor-create/actor-create.py +++ b/examples/python/actor-create/actor-create.py @@ -1,23 +1,25 @@ -# Copyright (c) 2006-2019. The SimGrid Team. All rights reserved. +# Copyright (c) 2006-2023. The SimGrid Team. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the license (GNU LGPL) which comes with this package. -# This example shows how to declare and start your actors. -# -# The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then -# you ask SimGrid to start your actors. There is three ways of doing so: -# - Directly, by instantiating your actor as parameter to Actor::create() -# - By first registering your actors before instantiating it; -# - Through the deployment file. -# -# This example shows all these solutions, even if you obviously should use only one of these solutions to start your -# actors. The most advised solution is to use a deployment file, as it creates a clear separation between your -# application and the settings to test it. This is a better scientific methodology. Actually, starting an actor with -# Actor.create() is mostly useful to start an actor from another actor. +""" +This example shows how to declare and start your actors. + +The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then +you ask SimGrid to start your actors. There is three ways of doing so: +- Directly, by instantiating your actor as parameter to Actor::create() +- By first registering your actors before instantiating it; +- Through the deployment file. + +This example shows all these solutions, even if you obviously should use only one of these solutions to start your +actors. The most advised solution is to use a deployment file, as it creates a clear separation between your +application and the settings to test it. This is a better scientific methodology. Actually, starting an actor with +Actor.create() is mostly useful to start an actor from another actor. +""" import sys -from simgrid import * +from simgrid import Actor, Engine, Host, Mailbox, this_actor def receiver(mailbox_name): @@ -59,10 +61,12 @@ class Sender: Later, this actor class is instantiated twice in the simulation. """ - def __init__(self, msg = "GaBuZoMeu", mbox = "mb42"): + def __init__(self, msg="GaBuZoMeu", mbox="mb42"): self.msg = msg self.mbox = mbox + # Actors that are created as object will execute their __call__ method. + # So, the following constitutes the main function of the Sender actor. def __call__(self): this_actor.info("Hello s4u, I have something to send") mailbox = Mailbox.by_name(self.mbox) @@ -72,7 +76,7 @@ class Sender: if __name__ == '__main__': - """Here comes the main function of your program""" + # Here comes the main function of your program # When your program starts, you have to first start a new simulation engine, as follows e = Engine(sys.argv)