Logo AND Algorithmique Numérique Distribuée

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