Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Pass the boolean parameter to the on_exit python binding
[simgrid.git] / examples / python / actor-lifetime / actor-lifetime.py
1 # Copyright (c) 2007-2022. 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 This Python file acts as the foil to the corresponding XML file, where the
8 action takes place: Actors are started and stopped at predefined time
9 """
10
11 import sys
12 from simgrid import Engine, this_actor
13
14
15 class Sleeper:
16     """This actor just sleeps until termination"""
17
18     def __init__(self):
19         this_actor.on_exit(lambda killed: this_actor.info("Exiting now (killed)." if killed else "Exiting now (finishing)."))
20
21     def __call__(self):
22         this_actor.info("Hello! I go to sleep.")
23         this_actor.sleep_for(10)
24         this_actor.info("Done sleeping.")
25
26
27 if __name__ == '__main__':
28     e = Engine(sys.argv)
29     if len(sys.argv) < 2:
30         raise AssertionError(
31             "Usage: actor-lifetime.py platform_file actor-lifetime_d.xml [other parameters]")
32
33     e.load_platform(sys.argv[1])     # Load the platform description
34     e.register_actor("sleeper", Sleeper)
35     # Deploy the sleeper actors with explicit start/kill times
36     e.load_deployment(sys.argv[2])
37
38     e.run()