Spawning process with another Qt app using multiprocessing from Python side
I'm probably missing something obvious, but with the test case
test.py
from multiprocessing import Process
def run_app():
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow
app = QApplication([__file__])
window = QMainWindow()
window.show()
app.exec_()
process = Process(target=run_app)
process.start()
test.qml
import QtQuick 2.4
import io.thp.pyotherside 1.4
Python {
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
importModule('test', function () {
console.log('test.py imported');
});
}
}
running qmlscene test.qml gives
estan@newton:~$ qmlscene test.qml
qml: test.py imported
WARNING: QApplication was not created in the main() thread.
and nothing shows up.
Running python3 test.py works fine of course.
Any idea why QApplication is giving a warning about not being created in the main thread? Both QApplications involved here (the one I spawn, and the one that drives the QML application) are created in completely different processes, so they should both be in the main thread of their respective processes, right?
(Some background, since I know this looks like a very contrived example: I'm working on the HMI GUI for an analysis machine. I communicate with the machine backend scripts using ZeroMQ sockets. When not running on the machine itself, I have a little simulator tool I built using Qt to simulate ZeroMQ messages from the machine. So for convenience while developing, I thought I'd just fire up the simulator process using multiprocessing from the Python side of my QML/pyotherside frontend, so that I get them both launched side by side.)