Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use different strings (and please sonar).
[simgrid.git] / examples / python / actor-join / actor-join.py
1 # Copyright (c) 2017-2020. The SimGrid Team. All rights reserved.
2 #
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.
5
6 from simgrid import Actor, Engine, Host, this_actor
7 import sys
8
9
10 def sleeper():
11     this_actor.info("Sleeper started")
12     this_actor.sleep_for(3)
13     this_actor.info("I'm done. See you!")
14
15
16 def master():
17     this_actor.info("Start 1st sleeper")
18     actor = Actor.create("1st sleeper from master", Host.current(), sleeper)
19     this_actor.info("Join the 1st sleeper (timeout 2)")
20     actor.join(2)
21
22     this_actor.info("Start 2nd sleeper")
23     actor = Actor.create("2nd sleeper from master", Host.current(), sleeper)
24     this_actor.info("Join the 2nd sleeper (timeout 4)")
25     actor.join(4)
26
27     this_actor.info("Start 3rd sleeper")
28     actor = Actor.create("3rd sleeper from master", Host.current(), sleeper)
29     this_actor.info("Join the 3rd sleeper (timeout 2)")
30     actor.join(2)
31
32     this_actor.info("Start 4th sleeper")
33     actor = Actor.create("4th sleeper from master", Host.current(), sleeper)
34     this_actor.info("Waiting 4")
35     this_actor.sleep_for(4)
36     this_actor.info("Join the 4th sleeper after its end (timeout 1)")
37     actor.join(1)
38
39     this_actor.info("Goodbye now!")
40
41     this_actor.sleep_for(1)
42
43     this_actor.info("Goodbye now!")
44
45
46 if __name__ == '__main__':
47     e = Engine(sys.argv)
48     if len(sys.argv) < 2:
49         raise AssertionError(
50             "Usage: actor-join.py platform_file [other parameters]")
51
52     e.load_platform(sys.argv[1])
53
54     Actor.create("master", Host.by_name("Tremblay"), master)
55
56     e.run()
57
58     this_actor.info("Simulation time {}".format(Engine.get_clock()))