Logo AND Algorithmique Numérique Distribuée

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