+ /* Class Actor */
+ py::class_<simgrid::s4u::Actor, ActorPtr>(m, "Actor",
+ "An actor is an independent stream of execution in your distributed "
+ "application, see :ref:`class s4u::Actor <API_s4u_Actor>`")
+ .def("create",
+ [](py::str name, Host* host, py::object fun, py::args args) {
+ return simgrid::s4u::Actor::create(name, host, [fun, args]() {
+ GilScopedAcquire py_context;
+ try {
+ fun(*args);
+ } catch (const py::error_already_set& ex) {
+ bool ffk = ex.matches(pyForcefulKillEx);
+ py_context.reset();
+ if (ffk) {
+ XBT_VERB("Actor killed");
+ /* Forward that ForcefulKill exception */
+ simgrid::ForcefulKillException::do_throw();
+ }
+ throw;
+ }
+ });
+ },
+ py::call_guard<GilScopedRelease>(), "Create an actor from a function or an object.")
+ .def_property("host", &Actor::get_host,
+ [](Actor* a, Host* h) {
+ GilScopedRelease gil_guard;
+ a->set_host(h);
+ },
+ "The host on which this actor is located")
+ .def_property_readonly("name", &Actor::get_cname, "The name of this actor.")
+ .def_property_readonly("pid", &Actor::get_pid, "The PID (unique identifier) of this actor.")
+ .def_property_readonly("ppid", &Actor::get_ppid,
+ "The PID (unique identifier) of the actor that created this one.")
+ .def("by_pid", &Actor::by_pid, "Retrieve an actor by its PID")
+ .def("daemonize", &Actor::daemonize, py::call_guard<GilScopedRelease>(),
+ "This actor will be automatically terminated when the last non-daemon actor finishes (more info in the C++ "
+ "documentation).")
+ .def("is_daemon", &Actor::is_daemon,
+ "Returns True if that actor is a daemon and will be terminated automatically when the last non-daemon actor "
+ "terminates.")
+ .def("join", py::overload_cast<double>(&Actor::join), py::call_guard<GilScopedRelease>(),
+ "Wait for the actor to finish (more info in the C++ documentation).", py::arg("timeout"))
+ .def("kill", &Actor::kill, py::call_guard<GilScopedRelease>(), "Kill that actor")
+ .def("kill_all", &Actor::kill_all, py::call_guard<GilScopedRelease>(), "Kill all actors but the caller.")
+ .def("self", &Actor::self, "Retrieves the current actor.")
+ .def("is_suspended", &Actor::is_suspended, "Returns True if that actor is currently suspended.")
+ .def("suspend", &Actor::suspend, py::call_guard<GilScopedRelease>(),
+ "Suspend that actor, that is blocked until resume()ed by another actor.")
+ .def("resume", &Actor::resume, py::call_guard<GilScopedRelease>(),
+ "Resume that actor, that was previously suspend()ed.");