From 1d64a0de445980c4bff7e31f9d9fc5ef372ff943 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 19 Mar 2014 20:51:58 -0400 Subject: fix meteor bugs with mira --- mteval/external_scorer.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'mteval/external_scorer.cc') diff --git a/mteval/external_scorer.cc b/mteval/external_scorer.cc index 1c09c2a1..f1b3ed6e 100644 --- a/mteval/external_scorer.cc +++ b/mteval/external_scorer.cc @@ -9,22 +9,34 @@ #include #include "stringlib.h" +#include "filelib.h" #include "tdict.h" using namespace std; +extern const char* meteor_jar_path; + map > ScoreServerManager::servers_; class METEORServer : public ScoreServer { public: - METEORServer() : ScoreServer("java -Xmx1024m -jar /usr0/cdyer/meteor/meteor-1.3.jar - - -mira -lower -t tune -l en") {} + METEORServer(const string& cmd) : ScoreServer(cmd) {} }; ScoreServer* ScoreServerManager::Instance(const string& score_type) { boost::shared_ptr& s = servers_[score_type]; if (!s) { if (score_type == "meteor") { - s.reset(new METEORServer); +#if HAVE_METEOR + if (!FileExists(meteor_jar_path)) { + cerr << meteor_jar_path << " not found!\n"; + abort(); + } + s.reset(new METEORServer(string("java -Xmx1536m -jar ") + meteor_jar_path + " - - -mira -lower -t tune -l en")); +#else + cerr << "cdec was not built with the --with-meteor option." << endl; + abort(); +#endif } else { cerr << "Don't know how to create score server for type '" << score_type << "'\n"; abort(); @@ -138,7 +150,11 @@ struct ExternalScore : public ScoreBase { assert(!"not implemented"); // no idea } void PlusEquals(const Score& delta, const float scale) { - assert(!"not implemented"); // don't even know what this is + if (static_cast(delta).score_server) score_server = static_cast(delta).score_server; + if (fields.size() != static_cast(delta).fields.size()) + fields.resize(max(fields.size(), static_cast(delta).fields.size())); + for (unsigned i = 0; i < static_cast(delta).fields.size(); ++i) + fields[i] += static_cast(delta).fields[i] * scale; } void PlusEquals(const Score& delta) { if (static_cast(delta).score_server) score_server = static_cast(delta).score_server; -- cgit v1.2.3 From 57767b8121f605b7e89e7a52c6d71be614399469 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 19 Mar 2014 23:01:55 -0400 Subject: don't get blocked on zombies --- mteval/external_scorer.cc | 7 +++++++ mteval/ns_ext.cc | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'mteval/external_scorer.cc') diff --git a/mteval/external_scorer.cc b/mteval/external_scorer.cc index f1b3ed6e..c7c3de1a 100644 --- a/mteval/external_scorer.cc +++ b/mteval/external_scorer.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ using namespace std; extern const char* meteor_jar_path; +extern void metric_child_signal_handler(int); map > ScoreServerManager::servers_; @@ -46,6 +48,11 @@ ScoreServer* ScoreServerManager::Instance(const string& score_type) { } ScoreServer::ScoreServer(const string& cmd) { + static bool need_init = true; + if (need_init) { + need_init = false; + signal(SIGCHLD, metric_child_signal_handler); + } cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } diff --git a/mteval/ns_ext.cc b/mteval/ns_ext.cc index 1e7e2bc1..9d2c75c6 100644 --- a/mteval/ns_ext.cc +++ b/mteval/ns_ext.cc @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -13,6 +15,14 @@ using namespace std; +void metric_child_signal_handler(int signo) { + int status = 0; + cerr << "Received SIGCHLD(" << signo << ") ... aborting.\n"; + // reap zombies + while (waitpid(-1, &status, WNOHANG) > 0) {} + abort(); +} + struct NScoreServer { NScoreServer(const std::string& cmd); ~NScoreServer(); @@ -27,6 +37,12 @@ struct NScoreServer { }; NScoreServer::NScoreServer(const string& cmd) { + static bool need_init = true; + if (need_init) { + need_init = false; + signal(SIGCHLD, metric_child_signal_handler); + } + cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } -- cgit v1.2.3 From 3cfb30225123e56e7ba85f5c92c79c16ffff995f Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 20 Mar 2014 12:47:17 -0400 Subject: fix crashes in mira --- mteval/external_scorer.cc | 10 +++------- mteval/ns_ext.cc | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 16 deletions(-) (limited to 'mteval/external_scorer.cc') diff --git a/mteval/external_scorer.cc b/mteval/external_scorer.cc index c7c3de1a..efd880fe 100644 --- a/mteval/external_scorer.cc +++ b/mteval/external_scorer.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -16,7 +15,7 @@ using namespace std; extern const char* meteor_jar_path; -extern void metric_child_signal_handler(int); +extern void setup_child_process_handler(); map > ScoreServerManager::servers_; @@ -48,11 +47,7 @@ ScoreServer* ScoreServerManager::Instance(const string& score_type) { } ScoreServer::ScoreServer(const string& cmd) { - static bool need_init = true; - if (need_init) { - need_init = false; - signal(SIGCHLD, metric_child_signal_handler); - } + setup_child_process_handler(); cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } @@ -83,6 +78,7 @@ ScoreServer::ScoreServer(const string& cmd) { } ScoreServer::~ScoreServer() { + cerr << "ScoreServer::~ScoreServer()\n"; // TODO close stuff, join stuff } diff --git a/mteval/ns_ext.cc b/mteval/ns_ext.cc index 9d2c75c6..efe48afe 100644 --- a/mteval/ns_ext.cc +++ b/mteval/ns_ext.cc @@ -10,17 +10,49 @@ #include #include +#include "filelib.h" #include "stringlib.h" #include "tdict.h" using namespace std; +static volatile bool child_need_init = true; + void metric_child_signal_handler(int signo) { int status = 0; - cerr << "Received SIGCHLD(" << signo << ") ... aborting.\n"; + string cmd; + { + ReadFile rf("/proc/self/cmdline"); + if (rf) getline(*rf.stream(), cmd); + } + for (unsigned i = 0; i < cmd.size(); ++i) + if (cmd[i] == 0) cmd[i] = ' '; + cerr << "Received SIGCHLD(" << signo << ")\n"; + if (cmd.size()) + cerr << " Parent command line: " << cmd << endl; + else + cerr << " Parent command line not available!\n"; // reap zombies - while (waitpid(-1, &status, WNOHANG) > 0) {} - abort(); + bool should_exit = false; + while (waitpid(-1, &status, WNOHANG) > 0) { + cerr << " Child status: " << status << (status ? " [FAILURE]" : " [OK]") << endl; + if (status) should_exit = true; + } + if (should_exit) { + cerr << "Exiting on account of non-zero child exit code...\n"; + exit(1); + } +} + +void setup_child_process_handler() { + if (child_need_init == true) { + child_need_init = false; + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_NOCLDSTOP; + sa.sa_handler = metric_child_signal_handler; + sigaction(SIGCHLD, &sa, NULL); + } } struct NScoreServer { @@ -37,12 +69,7 @@ struct NScoreServer { }; NScoreServer::NScoreServer(const string& cmd) { - static bool need_init = true; - if (need_init) { - need_init = false; - signal(SIGCHLD, metric_child_signal_handler); - } - + setup_child_process_handler(); cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } -- cgit v1.2.3 From 8e9652cf595aafa4acc7d67de967afdbca71ac75 Mon Sep 17 00:00:00 2001 From: Michael Denkowski Date: Thu, 20 Mar 2014 14:21:17 -0700 Subject: Include full argv (including command) as arg 2 of execvp() --- mteval/external_scorer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mteval/external_scorer.cc') diff --git a/mteval/external_scorer.cc b/mteval/external_scorer.cc index efd880fe..054c279e 100644 --- a/mteval/external_scorer.cc +++ b/mteval/external_scorer.cc @@ -63,10 +63,10 @@ ScoreServer::ScoreServer(const string& cmd) { cerr << "Exec'ing from child " << cmd << endl; vector vargs; SplitOnWhitespace(cmd, &vargs); - const char** cargv = static_cast(malloc(sizeof(const char*) * vargs.size())); - for (unsigned i = 1; i < vargs.size(); ++i) cargv[i-1] = vargs[i].c_str(); - cargv[vargs.size() - 1] = NULL; - execvp(vargs[0].c_str(), (char* const*)cargv); + const char** cargv = static_cast(malloc(sizeof(const char*) * (vargs.size() + 1))); + for (unsigned i = 0; i < vargs.size(); i++) cargv[i] = vargs[i].c_str(); + cargv[vargs.size()] = NULL; + execvp(*cargv, (char* const*)cargv); } else { // parent close(c2p[1]); close(p2c[0]); -- cgit v1.2.3