This commit is contained in:
David Rose 2009-08-19 01:34:34 +00:00
parent ec32604aa8
commit 625690fdb1
5 changed files with 19 additions and 9 deletions

View File

@ -32,7 +32,8 @@ P3DFileParams() {
P3DFileParams:: P3DFileParams::
P3DFileParams(const P3DFileParams &copy) : P3DFileParams(const P3DFileParams &copy) :
_p3d_filename(copy._p3d_filename), _p3d_filename(copy._p3d_filename),
_tokens(copy._tokens) _tokens(copy._tokens),
_args(copy._args)
{ {
} }
@ -45,6 +46,7 @@ void P3DFileParams::
operator = (const P3DFileParams &other) { operator = (const P3DFileParams &other) {
_p3d_filename = other._p3d_filename; _p3d_filename = other._p3d_filename;
_tokens = other._tokens; _tokens = other._tokens;
_args = other._args;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -63,6 +63,7 @@ P3DInstance(P3D_request_ready_func *func,
_got_wparams = false; _got_wparams = false;
_fparams.set_tokens(tokens, num_tokens); _fparams.set_tokens(tokens, num_tokens);
_fparams.set_args(argc, argv);
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
_instance_id = inst_mgr->get_unique_id(); _instance_id = inst_mgr->get_unique_id();

View File

@ -345,6 +345,8 @@ got_desc_file(TiXmlDocument *doc, bool freshly_downloaded) {
if (all_extracts_ok) { if (all_extracts_ok) {
// Great, we're ready to begin. // Great, we're ready to begin.
nout << "All " << _extracts.size() << " extracts of " << _package_name
<< " seem good.\n";
report_done(true); report_done(true);
} else { } else {

View File

@ -53,6 +53,7 @@ P3DSession(P3DInstance *inst) {
_python_version = inst->get_python_version(); _python_version = inst->get_python_version();
_start_dir = inst_mgr->get_root_dir() + "/start"; _start_dir = inst_mgr->get_root_dir() + "/start";
_p3dpython_started = false;
_p3dpython_running = false; _p3dpython_running = false;
_started_read_thread = false; _started_read_thread = false;
@ -82,7 +83,7 @@ P3DSession::
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DSession:: void P3DSession::
shutdown() { shutdown() {
if (_p3dpython_running) { if (_p3dpython_started) {
// Tell the process we're going away. // Tell the process we're going away.
TiXmlDocument doc; TiXmlDocument doc;
TiXmlElement *xcommand = new TiXmlElement("command"); TiXmlElement *xcommand = new TiXmlElement("command");
@ -159,6 +160,7 @@ shutdown() {
#endif // _WIN32 #endif // _WIN32
_p3dpython_running = false; _p3dpython_running = false;
_p3dpython_started = false;
} }
// If there are any leftover commands in the queue (presumably // If there are any leftover commands in the queue (presumably
@ -258,7 +260,7 @@ terminate_instance(P3DInstance *inst) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DSession:: void P3DSession::
send_command(TiXmlDocument *command) { send_command(TiXmlDocument *command) {
if (_p3dpython_running) { if (_p3dpython_started) {
// Python is running. Send the command. // Python is running. Send the command.
write_xml(_pipe_write, command, nout); write_xml(_pipe_write, command, nout);
delete command; delete command;
@ -285,7 +287,7 @@ send_command(TiXmlDocument *command) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TiXmlDocument *P3DSession:: TiXmlDocument *P3DSession::
command_and_response(TiXmlDocument *command) { command_and_response(TiXmlDocument *command) {
if (!_p3dpython_running) { if (!_p3dpython_started) {
return NULL; return NULL;
} }
@ -307,9 +309,6 @@ command_and_response(TiXmlDocument *command) {
while (ri == _responses.end()) { while (ri == _responses.end()) {
if (!_p3dpython_running) { if (!_p3dpython_running) {
// Hmm, looks like Python has gone away. // Hmm, looks like Python has gone away.
// TODO: make sure _p3dpython_running gets set to false when the
// process dies unexpectedly.
_response_ready.release(); _response_ready.release();
return NULL; return NULL;
} }
@ -593,7 +592,7 @@ signal_request_ready(P3DInstance *inst) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DSession:: void P3DSession::
drop_pyobj(int object_id) { drop_pyobj(int object_id) {
if (_p3dpython_running) { if (_p3dpython_started) {
TiXmlDocument doc; TiXmlDocument doc;
TiXmlElement *xcommand = new TiXmlElement("command"); TiXmlElement *xcommand = new TiXmlElement("command");
xcommand->SetAttribute("cmd", "drop_pyobj"); xcommand->SetAttribute("cmd", "drop_pyobj");
@ -641,7 +640,7 @@ report_packages_done(P3DInstance *inst, bool success) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DSession:: void P3DSession::
start_p3dpython(P3DInstance *inst) { start_p3dpython(P3DInstance *inst) {
if (_p3dpython_running) { if (_p3dpython_started) {
// Already started. // Already started.
return; return;
} }
@ -805,6 +804,7 @@ start_p3dpython(P3DInstance *inst) {
nout << "Failed to create process.\n"; nout << "Failed to create process.\n";
return; return;
} }
_p3dpython_started = true;
_p3dpython_running = true; _p3dpython_running = true;
if (!_pipe_read) { if (!_pipe_read) {
@ -880,6 +880,10 @@ rt_thread_run() {
if (doc == NULL) { if (doc == NULL) {
// Some error on reading. Abort. // Some error on reading. Abort.
rt_terminate(); rt_terminate();
_p3dpython_running = false;
_response_ready.acquire();
_response_ready.notify();
_response_ready.release();
return; return;
} }

View File

@ -118,6 +118,7 @@ private:
#else #else
int _p3dpython_pid; int _p3dpython_pid;
#endif #endif
bool _p3dpython_started;
bool _p3dpython_running; bool _p3dpython_running;
// The _response_ready mutex protects this structure. // The _response_ready mutex protects this structure.