-foreach(example actor-create actor-join actor-migrate actor-suspend actor-yield
+foreach(example actor-create actor-daemon actor-join actor-migrate actor-suspend actor-yield
exec-basic)
set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
--- /dev/null
+# Copyright (c) 2017-2018. The SimGrid Team. All rights reserved.
+#
+# This program is free software you can redistribute it and/or modify it
+# under the terms of the license (GNU LGPL) which comes with this package.
+
+from simgrid import *
+import sys
+
+# The worker process, working for a while before leaving
+def worker():
+ this_actor.info("Let's do some work (for 10 sec on Boivin).")
+ this_actor.execute(980.95e6)
+
+ this_actor.info("I'm done now. I leave even if it makes the daemon die.")
+
+# The daemon, displaying a message every 3 seconds until all other processes stop
+def my_daemon():
+ Actor.self().daemonize()
+
+ while True:
+ this_actor.info("Hello from the infinite loop")
+ this_actor.sleep_for(3.0)
+
+ this_actor.info("I will never reach that point: daemons are killed when regular processes are done")
+
+if __name__ == '__main__':
+ e = Engine(sys.argv)
+ if len(sys.argv) < 2: raise AssertionError("Usage: actor-daemon.py platform_file [other parameters]")
+
+ e.load_platform(sys.argv[1])
+ Actor.create("worker", Host.by_name("Boivin"), worker)
+ Actor.create("daemon", Host.by_name("Tremblay"), my_daemon)
+
+ e.run()
--- /dev/null
+#!/usr/bin/env tesh
+
+p Testing the process daemonization feature
+
+$ python3 ${bindir:=.}/actor-daemon.py ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" --cfg=contexts/factory:ucontext
+> [ 0.000000] (worker@Boivin) Let's do some work (for 10 sec on Boivin).
+> [ 0.000000] (daemon@Tremblay) Hello from the infinite loop
+> [ 3.000000] (daemon@Tremblay) Hello from the infinite loop
+> [ 6.000000] (daemon@Tremblay) Hello from the infinite loop
+> [ 9.000000] (daemon@Tremblay) Hello from the infinite loop
+> [ 10.000000] (worker@Boivin) I'm done now. I leave even if it makes the daemon die.
- **Daemonize actors:**
Some actors may be intended to simulate daemons that run in background. This example show how to transform a regular
actor into a daemon that will be automatically killed once the simulation is over.
- |br| `examples/s4u/actor-daemon/s4u-actor-daemon.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-daemon/s4u-actor-daemon.cpp>`_
+ |br| |cpp| `examples/s4u/actor-daemon/s4u-actor-daemon.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-daemon/s4u-actor-daemon.cpp>`_
+ |br| |py| `examples/python/actor-daemon/actor-daemon.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/actor-daemon/actor-daemon.py>`_
Inter-Actors Interactions
-------------------------