Skip to content

Commit

Permalink
Merge pull request #219 from SCIInstitute/py_help_fix
Browse files Browse the repository at this point in the history
Trap help() function to prevent interpreter hanging.
  • Loading branch information
Ayla Khan authored May 15, 2017
2 parents b973fd6 + 01e617b commit ef4bb4f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Core/Python/PythonInterpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <boost/python.hpp>
#include <boost/regex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/algorithm/string.hpp>

#include <sstream>

Expand Down Expand Up @@ -409,8 +410,21 @@ void PythonInterpreter::run_string( const std::string& command )
CORE_THROW_LOGICERROR( "The python interpreter hasn't been initialized!" );
}
}

if ( !this->is_eventhandler_thread() )

std::string trimmed_command = command;
boost::algorithm::trim( trimmed_command );
if ( trimmed_command == "help()" )
{
// trap help(), since it hangs interpreter and therefore the entire app
CORE_LOG_DEBUG( "Python help() trapped" );
PyErr_Clear();
PyRun_SimpleString("print(\"help() function ignored in interpreter\")\n");
this->private_->command_buffer_.clear();
this->prompt_signal_( this->private_->prompt1_ );
return;
}

if ( ! this->is_eventhandler_thread() )
{
{
PythonInterpreterPrivate::lock_type lock( this->private_->get_mutex() );
Expand Down Expand Up @@ -615,7 +629,6 @@ void PythonInterpreter::interrupt()
{
this->error_signal_( "\nKeyboardInterrupt\n" );
this->private_->command_buffer_.clear();
this->prompt_signal_( this->private_->prompt1_ );
}
}
}
Expand Down

0 comments on commit ef4bb4f

Please sign in to comment.