Skip to content
Snippets Groups Projects
Commit 35b80f7d authored by Marco Biasini's avatar Marco Biasini
Browse files

fix race condition in PythonInterpreterWorker that shows up when two nested...

fix race condition in PythonInterpreterWorker that shows up when two nested event loops trigger the Wake slot.
parent b7e49eee
No related branches found
No related tags found
No related merge requests found
...@@ -112,7 +112,8 @@ void FileBrowser::Init(const QString& path) ...@@ -112,7 +112,8 @@ void FileBrowser::Init(const QString& path)
view_->setRootIndex(model_->index(path)); view_->setRootIndex(model_->index(path));
view_->setAttribute(Qt::WA_MacShowFocusRect, false); view_->setAttribute(Qt::WA_MacShowFocusRect, false);
view_->setContextMenuPolicy(Qt::CustomContextMenu); view_->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view_,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ShowContextMenu(const QPoint&))); connect(view_,SIGNAL(customContextMenuRequested(const QPoint&)),this,
SLOT(ShowContextMenu(const QPoint&)));
UpdateMenu(path); UpdateMenu(path);
QVBoxLayout* l=new QVBoxLayout(this); QVBoxLayout* l=new QVBoxLayout(this);
......
...@@ -371,7 +371,8 @@ void FileLoader::RunScript(const QString& filename) ...@@ -371,7 +371,8 @@ void FileLoader::RunScript(const QString& filename)
pi.RunCommand("sys.argv.append('"+QFileInfo(filename).fileName()+"')"); pi.RunCommand("sys.argv.append('"+QFileInfo(filename).fileName()+"')");
pi.RunCommand("_dir=os.getcwd()"); pi.RunCommand("_dir=os.getcwd()");
pi.RunCommand("os.chdir('"+QFileInfo(filename).absolutePath()+"')"); pi.RunCommand("os.chdir('"+QFileInfo(filename).absolutePath()+"')");
pi.RunCommand("execfile('"+QFileInfo(filename).fileName()+"')"); pi.RunScript(QFileInfo(filename).fileName());
//pi.RunCommand("execfile('"+QFileInfo(filename).fileName()+"')");
pi.RunCommand("os.chdir(_dir)"); pi.RunCommand("os.chdir(_dir)");
pi.RunCommand("del(_dir)"); pi.RunCommand("del(_dir)");
pi.RunCommand("sys.argv=_sys_argv_backup"); pi.RunCommand("sys.argv=_sys_argv_backup");
......
...@@ -32,7 +32,8 @@ PythonInterpreterWorker::PythonInterpreterWorker(): ...@@ -32,7 +32,8 @@ PythonInterpreterWorker::PythonInterpreterWorker():
parse_expr_cmd_(), parse_expr_cmd_(),
repr_(), repr_(),
main_namespace_(), main_namespace_(),
current_id_() current_id_(),
awake_(false)
{ {
Py_InitializeEx(1); Py_InitializeEx(1);
parse_expr_cmd_=bp::import("parser").attr("expr"); parse_expr_cmd_=bp::import("parser").attr("expr");
...@@ -52,10 +53,14 @@ PythonInterpreterWorker::PythonInterpreterWorker(): ...@@ -52,10 +53,14 @@ PythonInterpreterWorker::PythonInterpreterWorker():
void PythonInterpreterWorker::Wake() void PythonInterpreterWorker::Wake()
{ {
if (awake_) return;
awake_=true;
while (!exec_queue_.isEmpty()){ while (!exec_queue_.isEmpty()){
std::pair<unsigned int, QString> pair=exec_queue_.dequeue(); std::pair<unsigned int, QString> pair=exec_queue_.dequeue();
run_command_(pair); run_command_(pair);
} }
awake_=false;
} }
unsigned int PythonInterpreterWorker::AddCommand(const QString& command) unsigned int PythonInterpreterWorker::AddCommand(const QString& command)
......
...@@ -46,6 +46,7 @@ protected: ...@@ -46,6 +46,7 @@ protected:
bp::object repr_; bp::object repr_;
bp::dict main_namespace_; bp::dict main_namespace_;
unsigned int current_id_; unsigned int current_id_;
bool awake_;
}; };
}} //ns }} //ns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment