don't have python try to intercept stdout/stderr

pull/1184/head
Thomas Winget 4 years ago
parent 32dbe6b1ad
commit 5cf35769b4

@ -29,12 +29,12 @@ namespace tooling
}
void
RouterHive::StartRouters(std::function<void(llarp_main *)> runFunc)
RouterHive::StartRouters()
{
for (llarp_main* ctx : routers)
{
routerMainThreads.emplace_back([runFunc, ctx](){
runFunc(ctx);
routerMainThreads.emplace_back([ctx](){
llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false});
});
std::this_thread::sleep_for(20ms);
}
@ -44,28 +44,40 @@ namespace tooling
RouterHive::StopRouters()
{
llarp::LogWarn("Signalling all routers to stop");
for (llarp_main* ctx : routers)
{
llarp_main_signal(ctx, 2 /* SIGINT */);
}
size_t i=0;
llarp::LogWarn("Waiting on routers to be stopped");
for (llarp_main* ctx : routers)
{
while(llarp_main_is_running(ctx))
{
llarp::LogWarn("Waiting on router ", i, " to stop");
std::this_thread::sleep_for(10ms);
}
i++;
}
//llarp::LogWarn("Joining router threads");
//i=0;
for (auto& thread : routerMainThreads)
{
//llarp::LogWarn("Attempting to join router thread ", i);
while (not thread.joinable())
{
llarp::LogWarn("Waiting for router thread to be joinable");
//llarp::LogWarn("Waiting on router thread ", i, " to be joinable");
std::this_thread::sleep_for(500ms);
}
thread.join();
//llarp::LogWarn("Joined router thread ", i);
//i++;
}
llarp::LogWarn("RouterHive::StopRouters finished");
}
void

@ -30,7 +30,7 @@ namespace tooling
AddRouter(const std::shared_ptr<llarp::Config> & conf);
void
StartRouters(std::function<void(llarp_main*)> runit);
StartRouters();
void
StopRouters();

@ -11,19 +11,7 @@ namespace tooling
py::class_< RouterHive, RouterHive_ptr >(mod, "RouterHive")
.def(py::init<>())
.def("AddRouter", &RouterHive::AddRouter)
.def("StartAll", [](RouterHive_ptr self) {
self->StartRouters([](llarp_main * ctx) {
py::scoped_ostream_redirect stream_0(
std::cout,
py::module::import("sys").attr("stdout")
);
py::scoped_ostream_redirect stream_1(
std::cerr,
py::module::import("sys").attr("stderr")
);
llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false});
});
})
.def("StartAll", &RouterHive::StartRouters)
.def("StopAll", &RouterHive::StopRouters)
.def("ForEachRouter", &RouterHive::ForEachRouter)
.def("VisitRouter", &RouterHive::VisitRouter)

Loading…
Cancel
Save