-# Copyright (c) 2017-2019. The SimGrid Team. All rights reserved.
+# Copyright (c) 2017-2022. 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.
-from simgrid import *
+"""
+Usage: actor-kill.py platform_file [other parameters]
+"""
+
import sys
+from simgrid import Actor, Engine, Host, this_actor
-def victimA_fun():
+def victim_a_fun():
this_actor.on_exit(lambda: this_actor.info("I have been killed!"))
this_actor.info("Hello!")
this_actor.info("Suspending myself")
this_actor.info("Bye!")
-def victimB_fun():
+def victim_b_fun():
this_actor.info("Terminate before being killed")
def killer():
- this_actor.info("Hello!") # - First start a victim process
- victimA = Actor.create("victim A", Host.by_name("Fafard"), victimA_fun)
- victimB = Actor.create("victim B", Host.by_name("Jupiter"), victimB_fun)
+ this_actor.info("Hello!") # - First start a victim actor
+ victim_a = Actor.create("victim A", Host.by_name("Fafard"), victim_a_fun)
+ victim_b = Actor.create("victim B", Host.by_name("Jupiter"), victim_b_fun)
this_actor.sleep_for(10) # - Wait for 10 seconds
# - Resume it from its suspended state
this_actor.info("Resume the victim A")
- victimA.resume()
+ victim_a.resume()
this_actor.sleep_for(2)
this_actor.info("Kill the victim A") # - and then kill it
- Actor.by_pid(victimA.pid).kill() # You can retrieve an actor from its PID (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 victimB, even if it's already dead")
- victimB.kill()
+ 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")
- victimC = Actor.create("victim C", Host.by_name("Jupiter"), victimA_fun)
- victimC.kill()
+ victim_c = Actor.create("victim C", Host.by_name("Jupiter"), victim_a_fun)
+ victim_c.kill()
this_actor.sleep_for(1)
"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
+ # Create and deploy killer actor, that will create the victim actors
Actor.create("killer", Host.by_name("Tremblay"), killer)
e.run()