Class: QgsBlockingProcess

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.

Class Hierarchy

Inheritance diagram of qgis.core.QgsBlockingProcess

Base classes

QObject

Methods

exitStatus

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

processError

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

run

Runs the process, and blocks until execution finishes.

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.

class qgis.core.QgsBlockingProcess[source]

Bases: QObject

__init__(program: str | None, arguments: Iterable[str | None])

Constructor for the given program, with the specified list of arguments.

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

Parameters:
  • program (Optional[str])

  • arguments (Iterable[Optional[str]])

exitStatus(self) QProcess.ExitStatus[source]

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

Return type:

QProcess.ExitStatus

processError(self) QProcess.ProcessError[source]

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

Returns QProcess.UnknownError if no error occurred.

Return type:

QProcess.ProcessError

run(self, feedback: QgsFeedback | None = None) int[source]

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

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

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

Parameters:

a0 (Optional[Callable[..., None]])

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

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

Parameters:

a0 (Optional[Callable[..., None]])