def victim_a_fun():
- this_actor.on_exit(lambda: this_actor.info("I have been killed!"))
+ this_actor.on_exit(lambda forcefully: this_actor.info("I have been killed!" if forcefully else "I finish now."))
this_actor.info("Hello!")
this_actor.info("Suspending myself")
this_actor.suspend() # - Start by suspending itself
"""This actor just sleeps until termination"""
def __init__(self):
- this_actor.on_exit(lambda: this_actor.info("Exiting now (done sleeping or got killed)."))
+ this_actor.on_exit(lambda killed: this_actor.info("Exiting now (killed)." if killed else "Exiting now (finishing)."))
def __call__(self):
this_actor.info("Hello! I go to sleep.")
> [ 0.000000] (1:sleeper@node-0.simgrid.org) Hello! I go to sleep.
> [ 0.000000] (2:sleeper@node-1.simgrid.org) Hello! I go to sleep.
> [ 2.000000] (3:sleeper@node-0.simgrid.org) Hello! I go to sleep.
-> [ 3.000000] (2:sleeper@node-1.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 3.000000] (2:sleeper@node-1.simgrid.org) Exiting now (killed).
> [ 4.000000] (4:sleeper@node-2.simgrid.org) Hello! I go to sleep.
-> [ 7.000000] (4:sleeper@node-2.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 7.000000] (4:sleeper@node-2.simgrid.org) Exiting now (killed).
> [ 10.000000] (1:sleeper@node-0.simgrid.org) Done sleeping.
-> [ 10.000000] (1:sleeper@node-0.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 10.000000] (1:sleeper@node-0.simgrid.org) Exiting now (finishing).
> [ 12.000000] (3:sleeper@node-0.simgrid.org) Done sleeping.
-> [ 12.000000] (3:sleeper@node-0.simgrid.org) Exiting now (done sleeping or got killed).
+> [ 12.000000] (3:sleeper@node-0.simgrid.org) Exiting now (finishing).
[](py::object cb) {
py::function fun = py::reinterpret_borrow<py::function>(cb);
fun.inc_ref(); // FIXME: why is this needed for tests like actor-kill and actor-lifetime?
- simgrid::s4u::this_actor::on_exit([fun](bool /*failed*/) {
+ simgrid::s4u::this_actor::on_exit([fun](bool failed) {
py::gil_scoped_acquire py_context; // need a new context for callback
try {
- fun();
+ fun(failed);
} catch (const py::error_already_set& e) {
xbt_die("Error while executing the on_exit lambda: %s", e.what());
}
});
},
- py::call_guard<py::gil_scoped_release>(), "")
+ py::call_guard<py::gil_scoped_release>(),
+ "Define a lambda to be called when the actor ends. It takes a bool parameter indicating whether the actor "
+ "was killed. If False, the actor finished peacefully.")
.def("get_pid", &simgrid::s4u::this_actor::get_pid, "Retrieves PID of the current actor")
.def("get_ppid", &simgrid::s4u::this_actor::get_ppid,
"Retrieves PPID of the current actor (i.e., the PID of its parent).");