From 703dbd9c798f4a373f8c48c477a4a67fc7ae9408 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 27 Apr 2022 18:57:02 +0200 Subject: [PATCH] QtcProcess: Add a warning when starting a process in non-QThread When a QProcess is being started in a thread that doesn't have event dispatcher installed, e.g. in a thread started with std::async(), the process signals are emitted only from inside QProcess::waitFor...() functions, but not emitted spontaneously. This may cause issues when adding the running process into the ProcessReaper, as the implementation of the latter relies on signal emission and doesn't use blocking API of QProcess. Currently there is one case like this: ProcessCreator::createProcess() of clangsupport library. Change-Id: I823a139b356f62fee9e0e5d6fc8326301c36b449 Reviewed-by: hjk Reviewed-by: --- src/libs/utils/qtcprocess.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index 4845cc8f4b8..73ef55bb038 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -367,6 +367,9 @@ private: void doDefaultStart(const QString &program, const QStringList &arguments) final { + QTC_ASSERT(QThread::currentThread()->eventDispatcher(), + qWarning("QtcProcess::start(): Starting a process in a non QThread thread " + "may cause infinite hang when destroying the running process.")); ProcessStartHandler *handler = m_process->processStartHandler(); handler->setProcessMode(m_setup.m_processMode); handler->setWriteData(m_setup.m_writeData);