Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New python example: actor-daemon
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 8 Jan 2019 03:57:18 +0000 (04:57 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 8 Jan 2019 03:57:18 +0000 (04:57 +0100)
examples/python/CMakeLists.txt
examples/python/actor-daemon/actor-daemon.py [new file with mode: 0644]
examples/python/actor-daemon/actor-daemon.tesh [new file with mode: 0644]
examples/s4u/README.rst

index 367f795..6f1c596 100644 (file)
@@ -1,4 +1,4 @@
-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)
                 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)
diff --git a/examples/python/actor-daemon/actor-daemon.py b/examples/python/actor-daemon/actor-daemon.py
new file mode 100644 (file)
index 0000000..c8dc581
--- /dev/null
@@ -0,0 +1,34 @@
+# 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()
diff --git a/examples/python/actor-daemon/actor-daemon.tesh b/examples/python/actor-daemon/actor-daemon.tesh
new file mode 100644 (file)
index 0000000..e3b4ec6
--- /dev/null
@@ -0,0 +1,11 @@
+#!/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.
index 8c6c87b..53f349b 100644 (file)
@@ -56,7 +56,8 @@ Starting and Stoping Actors
   - **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.
   - **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
 -------------------------
     
 Inter-Actors Interactions
 -------------------------