Skip to content

Commit 0c1ee4b

Browse files
authored
Merge pull request bruderstein#51 from bruderstein/console-gil-fixes
Console GIL fixes
2 parents 16a4e5f + 4c3a445 commit 0c1ee4b

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

PythonScript/src/PythonConsole.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void PythonConsole::initPython(PythonHandler *pythonHandler)
121121
void PythonConsole::pythonShowDialog()
122122
{
123123
assert(mp_consoleDlg);
124+
GILRelease release;
124125
if (mp_consoleDlg)
125126
{
126127
// Post the message to ourselves (on the right thread) to create the window
@@ -144,6 +145,7 @@ void PythonConsole::showDialog()
144145
assert(mp_consoleDlg);
145146
if (mp_consoleDlg)
146147
{
148+
GILRelease release;
147149
mp_consoleDlg->doDialog();
148150
}
149151
}
@@ -153,6 +155,7 @@ void PythonConsole::hideDialog()
153155
assert(mp_consoleDlg);
154156
if (mp_consoleDlg)
155157
{
158+
GILRelease release;
156159
mp_consoleDlg->hide();
157160
}
158161
}
@@ -162,6 +165,7 @@ void PythonConsole::message(const char *msg)
162165
assert(mp_consoleDlg);
163166
if (mp_consoleDlg)
164167
{
168+
GILRelease release;
165169
mp_consoleDlg->writeText(strlen(msg), msg);
166170
}
167171
}
@@ -171,6 +175,7 @@ void PythonConsole::clear()
171175
assert(mp_consoleDlg);
172176
if (mp_consoleDlg)
173177
{
178+
GILRelease release;
174179
mp_consoleDlg->clearText();
175180
}
176181
}
@@ -272,23 +277,26 @@ void PythonConsole::queueComplete()
272277

273278
void PythonConsole::consume(std::shared_ptr<std::string> statement)
274279
{
275-
GILLock gilLock;
276-
277280
bool continuePrompt = false;
278-
try
279-
{
280-
boost::python::object oldStdout = m_sys.attr("stdout");
281-
m_sys.attr("stdout") = boost::python::ptr(this);
282-
PyObject* unicodeCommand = PyUnicode_FromEncodedObject(boost::python::str(statement->c_str()).ptr(), "utf-8", NULL);
283-
boost::python::object result = m_pushFunc(boost::python::handle<PyObject>(unicodeCommand));
284-
//Py_DECREF(unicodeCommand);
285-
m_sys.attr("stdout") = oldStdout;
286-
287-
continuePrompt = boost::python::extract<bool>(result);
288-
}
289-
catch(...)
290281
{
291-
PyErr_Print();
282+
GILLock gilLock;
283+
284+
try
285+
{
286+
boost::python::object oldStdout = m_sys.attr("stdout");
287+
m_sys.attr("stdout") = boost::python::ptr(this);
288+
PyObject* unicodeCommand = PyUnicode_FromEncodedObject(boost::python::str(statement->c_str()).ptr(), "utf-8", NULL);
289+
boost::python::object result = m_pushFunc(boost::python::handle<PyObject>(unicodeCommand));
290+
//Py_DECREF(unicodeCommand);
291+
m_sys.attr("stdout") = oldStdout;
292+
293+
continuePrompt = boost::python::extract<bool>(result);
294+
}
295+
catch(...)
296+
{
297+
PyErr_Print();
298+
}
299+
292300
}
293301

294302
assert(mp_consoleDlg);

0 commit comments

Comments
 (0)