Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d82b20fcbb630883efa9afcb9cda30bd7a43d8b8
[simgrid.git] / examples / python / actor-yield / actor-yield.py
1 # Copyright (c) 2017-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 example does not much: It just spans over-polite actor that yield a large amount
8 of time before ending.
9
10 This serves as an example for the simgrid.yield() function, with which an actor can request
11 to be rescheduled after the other actor that are ready at the current timestamp.
12
13 It can also be used to benchmark our context-switching mechanism.
14 """
15
16 import sys
17 from simgrid import Actor, Engine, Host, this_actor
18
19 def yielder(number_of_yields):
20     for _ in range(number_of_yields):
21         this_actor.yield_()
22     this_actor.info("I yielded {:d} times. Goodbye now!".format(number_of_yields))
23
24 if __name__ == '__main__':
25     e = Engine(sys.argv)
26
27     e.load_platform(sys.argv[1])             # Load the platform description
28
29     Actor.create("yielder", Host.by_name("Tremblay"), yielder, 10)
30     Actor.create("yielder", Host.by_name("Ruby"), yielder, 15)
31
32     e.run()  # - Run the simulation