Commit b88d1b0a authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

python: allow changing of final_time attribute on simulation instances

parent 5e5f41e7
......@@ -111,6 +111,9 @@ namespace Python {
static PyObject* removeEventFD(Simulation *self, PyObject *args);
static PyObject* setScheduler(Simulation *self, PyObject *args, PyObject *kwargs);
// Setters
static int setFinalTime(Simulation *self, PyObject *val, void *ctx);
// Getters
static PyObject* getState(Simulation *self, void *ctx);
static PyObject* name(Simulation *self, void *ctx);
......@@ -701,6 +701,18 @@ PyObject* Python::Simulation::avgStepTime(Simulation *self, void *ctx)
return Py_BuildValue("f", avg);
int Python::Simulation::setFinalTime(Simulation *self, PyObject *val, void *ctx)
std::unique_lock<std::mutex> lk(*self->mut);
if (val == nullptr)
return -1;
return 0;
// TODO: for everything but state, we could use read-only Attributes and a getattro
// implementation that locks the mutex before access
PyGetSetDef Python::Simulation::getset[] = {
......@@ -708,7 +720,7 @@ PyGetSetDef Python::Simulation::getset[] = {
{(char *) "name", (getter) Python::Simulation::name, nullptr, (char *) Python::Simulation::docName, nullptr},
{(char *) "steps", (getter) Python::Simulation::steps, nullptr, nullptr, nullptr},
{(char *) "time", (getter) Python::Simulation::time, nullptr, nullptr, nullptr},
{(char *) "final_time", (getter) Python::Simulation::finalTime, nullptr, nullptr, nullptr},
{(char *) "final_time", (getter) Python::Simulation::finalTime, (setter) Python::Simulation::setFinalTime, nullptr, nullptr},
{(char *) "avg_step_time", (getter) Python::Simulation::avgStepTime, nullptr, nullptr, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
......@@ -47,7 +47,7 @@ Simulation::Simulation(String name, Logger::Level logLevel) :
mName(name), mLogLevel(logLevel) {
addAttribute<String>("name", &mName, Flags::read);
addAttribute<Real>("final_time", &mFinalTime, Flags::read);
addAttribute<Real>("final_time", &mFinalTime, Flags::read|Flags::write);
// Logging
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment