For one plugin I maintain, I can't figure out how to return output layer when the user hits 'Cancel'. Basically I'm looping over a set of results in processAlgorithm which populates the output layer and I'd expect to have the output layer returned with all results calculated until 'Cancel' was clicked.

A minimal example:

def processAlgorithm(self, parameters, context, feedback):
    (sink, self.dest_id) = self.parameterAsSink(parameters, 'Output', context,

    for result in results:
        if feedback.isCanceled():

        # Do smth smart


    return {'Output': self.dest_id}

However, no layer is added to the map when 'Cancel' is hit mid-way through processing.

EDIT Just to clarify, I'd have expected that if feedback.isCanceled(): break would yield return {'Output': self.dest_id}, i.e. the output layer with the added features until feedback.isCanceled() is called.

1 Answer 1


Asked the same question on the QGIS dev mailing list and according to @nyalldawson this is intended behavior, so as not to receive misleading partial results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.