我们正在尝试通过PythonQT控制台在 QT C++ 应用程序中使用matlab 引擎。普通的 python 命令在我们的应用程序的 pythonQT 控制台中工作,但是当我们尝试连接到 matlab 引擎时,它会在函数调用处挂起(参见问题末尾的堆栈跟踪第 6 行)。MatlabEngine::waitForMATLAB
我们有一个 Matlab 实例正在运行,它的引擎通过调用来共享matlab.engine.shareEngine
。在 PythonQT 控制台上,我们通过
eng = matlab.engine.connect_matlab('XXXX')
. 这会导致引擎(?)冻结。
注意:直接从通用 python 终端连接到matlab 引擎没有问题。我们只有在从 PythonQT 终端中访问它时才会遇到这个问题。
堆栈跟踪:
1 __psynch_cvwait
2 _pthread_cond_wait
3 std::condition_variable::__do_timed_wait(std::unique_lock<std::mutex>&, std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long long, std::ratio<1l, 1000000000l>>>)
4 std::cv_status std::condition_variable::wait_for<long long, std::ratio<1l, 1000000000l>>(std::unique_lock<std::mutex>&, std::chrono::duration<long long, std::ratio<1l, 1000000000l>> const&)
5 std::future_status std::__assoc_sub_state::wait_until<std::chrono::steady_clock, std::chrono::duration<long long, std::ratio<1l, 1000000000l>>>(std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<long long, std::ratio<1l, 1000000000l>>> const&) const
6 engine_api::waitMATLAB(unsigned long long, double)
7 MatlabEngine::waitForMATLAB(_object *, _object *)
8 PyEval_EvalFrameEx
9 ___lldb_unnamed_symbol1476$$Python
10 PyEval_EvalFrameEx
11 PyEval_EvalCodeEx
12 ___lldb_unnamed_symbol1476$$Python
13 PyEval_EvalFrameEx
14 PyEval_EvalCodeEx
15 ___lldb_unnamed_symbol1476$$Python
16 PyEval_EvalFrameEx
17 PyEval_EvalCodeEx
18 ___lldb_unnamed_symbol1476$$Python
19 PyEval_EvalFrameEx
20 PyEval_EvalCodeEx
21 PyEval_EvalCode
22 ___lldb_unnamed_symbol1599$$Python
23 PyRun_StringFlags
24 PythonQtScriptingConsole::executeCode(QString const&)
25 PythonQtScriptingConsole::executeLine(bool)
26 PythonQtScriptingConsole::keyPressEvent(QKeyEvent *)
27 QWidget::event(QEvent *)
28 QFrame::event(QEvent *)
29 QAbstractScrollArea::event(QEvent *)
30 QTextEdit::event(QEvent *)
31 QApplicationPrivate::notify_helper(QObject *, QEvent *)
32 QApplication::notify(QObject *, QEvent *)
33 QCoreApplication::notifyInternal2(QObject *, QEvent *)
34 ___lldb_unnamed_symbol542$$QtWidgets
35 QApplicationPrivate::notify_helper(QObject *, QEvent *)
36 QApplication::notify(QObject *, QEvent *)
37 QCoreApplication::notifyInternal2(QObject *, QEvent *)
38 QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *)
39 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)
40 QWindowSystemInterface::flushWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)
41 ___lldb_unnamed_symbol405$$libqcocoa.dylib
42 ___lldb_unnamed_symbol406$$libqcocoa.dylib
43 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
44 -[NSWindow(NSEventRouting) sendEvent:]
45 ___lldb_unnamed_symbol169$$libqcocoa.dylib
46 ___lldb_unnamed_symbol152$$libqcocoa.dylib
47 -[NSApplication(NSEvent) sendEvent:]
48 ___lldb_unnamed_symbol583$$libqcocoa.dylib
49 -[NSApplication run]
50 ___lldb_unnamed_symbol505$$libqcocoa.dylib
51 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)
52 QCoreApplication::exec()
53 main
54 start
我在 Matlab 论坛上有一个未解决的问题,目前还没有答案。
任何帮助或指针表示赞赏:)
新台币