Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
victim_a.resume()
this_actor.sleep_for(2)
this_actor.info("Kill the victim A") # - and then kill it
Actor.by_pid(victim_a.pid).kill() # You can retrieve an actor from its PID (and then kill it)
this_actor.sleep_for(1)
# that's a no-op, there is no zombies in SimGrid
this_actor.info("Kill victim B, even if it's already dead")
victim_b.kill()
this_actor.sleep_for(1)
this_actor.info("Start a new actor, and kill it right away")
victim_c = Actor.create("victim C", Host.by_name("Jupiter"), victim_a_fun)
victim_c.kill()
this_actor.sleep_for(1)
this_actor.info("Killing everybody but myself")
Actor.kill_all()
this_actor.info("OK, goodbye now. I commit a suicide.")
this_actor.exit()
this_actor.info(
"This line never gets displayed: I'm already dead since the previous line.")
def __call__(self):
fafard = Host.by_name("Fafard")
ginette = Host.by_name("Ginette")
boivin = Host.by_name("Boivin")
this_actor.info("I'm a wizard! I can run a task on the Ginette host from the Fafard one! Look!")
activity = this_actor.exec_init(48.492e6)
activity.host = ginette
activity.start()
this_actor.info("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).")
this_actor.sleep_for(0.1)
this_actor.info("Loads in flops/s: Boivin={:.0f}; Fafard={:.0f}; Ginette={:.0f}".format(boivin.load, fafard.load,
ginette.load))
activity.wait()
this_actor.info("Done!")
this_actor.info("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec")
activity = this_actor.exec_init(73293500)
this_actor.info("OK, goodbye now. I commit a suicide.")
this_actor.exit()
this_actor.info(
"This line never gets displayed: I'm already dead since the previous line.")
if __name__ == '__main__':
e = Engine(sys.argv)
if len(sys.argv) < 2:
raise AssertionError(
"Usage: actor-kill.py platform_file [other parameters]")
e.load_platform(sys.argv[1]) # Load the platform description
# Create and deploy killer process, that will create the victim actors
Actor.create("killer", Host.by_name("Tremblay"), killer)
e.run()
def master():
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 2)")
actor.join(2)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 4)")
actor.join(4)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 2)")
actor.join(2)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Waiting 4")
# So instead of a half/half sharing between the two executions,
# we get a 1/3 vs 2/3 sharing.
this_actor.execute(98095, priority=2)
this_actor.info("Done.")
# Note that the timings printed when executing this example are a bit misleading,
# because the uneven sharing only last until the privileged actor ends.
# After this point, the unprivileged one gets 100% of the CPU and finishes
# quite quickly.
if __name__ == '__main__':
e = Engine(sys.argv)
e.load_platform(sys.argv[1])
Actor.create("executor", Host.by_name("Tremblay"), executor)
Actor.create("privileged", Host.by_name("Tremblay"), privileged)
e.run()
this_actor.info("I changed my mind, cancel!")
activity.cancel()
this_actor.info("Goodbye now!")
if __name__ == '__main__':
e = Engine(sys.argv)
if len(sys.argv) < 2:
raise AssertionError("Usage: exec-async.py platform_file [other parameters]")
e.load_platform(sys.argv[1])
Actor.create("wait", Host.by_name("Fafard"), Waiter())
Actor.create("monitor", Host.by_name("Ginette"), Monitor())
Actor.create("cancel", Host.by_name("Boivin"), Canceller())
e.run()
e.load_platform("../../platforms/small_platform.xml")
# And now you have to ask SimGrid to actually start your actors.
#
# The easiest way to do so is to implement the behavior of your actor in a single function,
# as we do here for the receiver actors. This function can take any kind of parameters, as
# long as the last parameters of Actor::create() match what your function expects.
Actor.create("receiver", Host.by_name("Fafard"), receiver, "mb42")
# If your actor is getting more complex, you probably want to implement it as a class instead,
# as we do here for the sender actors. The main behavior goes into operator()() of the class.
#
# You can then directly start your actor, as follows:
Actor.create("sender1", Host.by_name("Tremblay"), Sender())
# If you want to pass parameters to your class, that's very easy: just use your constructors
Actor.create("sender2", Host.by_name("Jupiter"), Sender("GloubiBoulga"))
# But starting actors directly is considered as a bad experimental habit, since it ties the code
# you want to test with the experimental scenario. Starting your actors from an external deployment
# file in XML ensures that you can test your code in several scenarios without changing the code itself.
#
# For that, you first need to register your function or your actor as follows.
e.register_actor("sender", Sender)
e.register_actor("forwarder", forwarder)
# Once actors and functions are registered, just load the deployment file
e.load_deployment("actor-create_d.xml")
# Once every actors are started in the engine, the simulation can start
e.run()
while True:
this_actor.info("Hello from the infinite loop")
this_actor.sleep_for(3.0)
this_actor.info(
"I will never reach that point: daemons are killed when regular processes are done")
if __name__ == '__main__':
e = Engine(sys.argv)
if len(sys.argv) < 2:
raise AssertionError(
"Usage: actor-daemon.py platform_file [other parameters]")
e.load_platform(sys.argv[1])
Actor.create("worker", Host.by_name("Boivin"), worker)
Actor.create("daemon", Host.by_name("Tremblay"), my_daemon)
e.run()
this_actor.info("Hello from the infinite loop")
this_actor.sleep_for(3.0)
this_actor.info(
"I will never reach that point: daemons are killed when regular processes are done")
if __name__ == '__main__':
e = Engine(sys.argv)
if len(sys.argv) < 2:
raise AssertionError(
"Usage: actor-daemon.py platform_file [other parameters]")
e.load_platform(sys.argv[1])
Actor.create("worker", Host.by_name("Boivin"), worker)
Actor.create("daemon", Host.by_name("Tremblay"), my_daemon)
e.run()
this_actor.info("Goodbye now!")
this_actor.sleep_for(1)
this_actor.info("Goodbye now!")
if __name__ == '__main__':
e = Engine(sys.argv)
if len(sys.argv) < 2:
raise AssertionError(
"Usage: actor-join.py platform_file [other parameters]")
e.load_platform(sys.argv[1])
Actor.create("master", Host.by_name("Tremblay"), master)
e.run()
this_actor.info("Simulation time {}".format(Engine.get_clock()))