1 # Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
7 Usage: actor-kill.py platform_file [other parameters]
11 from simgrid import Actor, Engine, Host, this_actor
15 this_actor.on_exit(lambda forcefully: this_actor.info("I have been killed!" if forcefully else "I finish now."))
16 this_actor.info("Hello!")
17 this_actor.info("Suspending myself")
18 this_actor.suspend() # - Start by suspending itself
19 # - Then is resumed and start to execute a task
20 this_actor.info("OK, OK. Let's work")
21 this_actor.execute(1e9)
22 # - But will never reach the end of it
23 this_actor.info("Bye!")
27 this_actor.info("Terminate before being killed")
31 this_actor.info("Hello!") # - First start a victim actor
32 victim_a = Actor.create("victim A", Host.by_name("Fafard"), victim_a_fun)
33 victim_b = Actor.create("victim B", Host.by_name("Jupiter"), victim_b_fun)
34 this_actor.sleep_for(10) # - Wait for 10 seconds
36 # - Resume it from its suspended state
37 this_actor.info("Resume the victim A")
39 this_actor.sleep_for(2)
41 this_actor.info("Kill the victim A") # - and then kill it
42 Actor.by_pid(victim_a.pid).kill() # You can retrieve an actor from its PID (and then kill it)
44 this_actor.sleep_for(1)
46 # that's a no-op, there is no zombies in SimGrid
47 this_actor.info("Kill victim B, even if it's already dead")
50 this_actor.sleep_for(1)
52 this_actor.info("Start a new actor, and kill it right away")
53 victim_c = Actor.create("victim C", Host.by_name("Jupiter"), victim_a_fun)
56 this_actor.sleep_for(1)
58 this_actor.info("Killing everybody but myself")
61 this_actor.info("OK, goodbye now. I commit a suicide.")
65 "This line never gets displayed: I'm already dead since the previous line.")
68 if __name__ == '__main__':
72 "Usage: actor-kill.py platform_file [other parameters]")
74 e.load_platform(sys.argv[1]) # Load the platform description
75 # Create and deploy killer actor, that will create the victim actors
76 Actor.create("killer", Host.by_name("Tremblay"), killer)