Class: QgsBlockingProcess

class qgis.core.QgsBlockingProcess

Bases: PyQt5.QtCore.QObject

A thread safe class for performing blocking (sync) execution of external processes.

This class should be used whenever a blocking process run is required. Unlike implementations which rely on QApplication.processEvents() or creation of a QEventLoop, this class is completely thread safe and can be used on either the main thread or background threads without issue.

Not available on some platforms (e.g. iOS) https://lists.qt-project.org/pipermail/development/2015-July/022205.html

Added in version 3.18.

QgsBlockingProcess(program: Optional[str], arguments: Iterable[Optional[str]]) Constructor for the given program, with the specified list of arguments.

After construction, call run() to start the process execution.

Methods

childEvent

connectNotify

customEvent

disconnectNotify

exitStatus

After a call to run(), returns the process' exit status.

isSignalConnected

processError

After a call to run(), returns the process' reported error.

receivers

run

Runs the process, and blocks until execution finishes.

sender

senderSignalIndex

setStdErrHandler

Sets a handler function to call whenever content is written by the process to stderr.

setStdOutHandler

Sets a handler function to call whenever content is written by the process to stdout.

timerEvent

childEvent(self, a0: QChildEvent | None)
connectNotify(self, signal: QMetaMethod)
customEvent(self, a0: QEvent | None)
disconnectNotify(self, signal: QMetaMethod)
exitStatus(self) QProcess.ExitStatus

After a call to run(), returns the process’ exit status.

Return type:

QProcess.ExitStatus

isSignalConnected(self, signal: QMetaMethod) bool
processError(self) QProcess.ProcessError

After a call to run(), returns the process’ reported error.

Returns QProcess.UnknownError if no error occurred.

Return type:

QProcess.ProcessError

receivers(self, signal: PYQT_SIGNAL) int
run(self, feedback: QgsFeedback | None = None) int

Runs the process, and blocks until execution finishes.

The optional feedback argument can be used to specify a feedback object for cancellation/process termination.

After execution completes, the process’ result code will be returned.

Parameters:

feedback (Optional[QgsFeedback] = None)

Return type:

int

sender(self) QObject | None
senderSignalIndex(self) int
setStdErrHandler(self, a0: Callable[..., None] | None)

Sets a handler function to call whenever content is written by the process to stderr.

Parameters:

a0 (Optional[Callable[...)

setStdOutHandler(self, a0: Callable[..., None] | None)

Sets a handler function to call whenever content is written by the process to stdout.

Parameters:

a0 (Optional[Callable[...)

timerEvent(self, a0: QTimerEvent | None)