Logo AND Algorithmique Numérique Distribuée

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