assert(modules.count(py_module->get_name()) == 0);
modules[py_module->get_name()].reset(new ActivePyModule(py_module, clog));
+ auto active_module = modules.at(py_module->get_name()).get();
- int r = modules[py_module->get_name()]->load(this);
+ int r = active_module->load(this);
if (r != 0) {
return r;
} else {
dout(4) << "Starting thread for " << py_module->get_name() << dendl;
- // Giving Thread the module's module_name member as its
- // char* thread name: thread must not outlive module class lifetime.
- modules[py_module->get_name()]->thread.create(
- py_module->get_name().c_str());
+ active_module->thread.create(active_module->get_thread_name());
return 0;
}
void *entry() override;
};
+ std::string thread_name;
public:
int serve();
void shutdown();
void log(int level, const std::string &record);
+ const char *get_thread_name() const
+ {
+ return thread_name.c_str();
+ }
+
PyModuleRunner(
const PyModuleRef &py_module_,
LogChannelRef clog_)
clog(clog_),
thread(this)
{
+ // Shortened name for use as thread name, because thread names
+ // required to be <16 chars
+ thread_name = py_module->get_name().substr(0, 15);
+
assert(py_module != nullptr);
}