I don't understand how "is_child_algorithm" works in processing.run.
Premise: I created a script in python. This script uses a loop, iterating thousands of times over a field on a layer. I noticed that the ram occupation grows over time and the processing time on the single step also grows. I use different "classical" functions in the code ex:
outputs['fieldcalculator_on_layer_map1'] = processing.run ('native: fieldcalculator', alg_params, context = context, is_child_algorithm = True)
outputs ['delete_duplicate_on_layer_map1'] = processing.run ('native: deleteduplicategeometries', alg_params, context = context, is_child_algorithm = True)
I noticed that setting is_child_algorithm = False I don't have the ram and time problem (it remains constant at each step), but after several iterations (200) the program crashes, while using is_child_algorithm = True doesn't crash, of course.
What does "is_child_algorithm = True / False" do?
1 Answer 1
According to QGIS source code the is_child_algorithm
parameter is used to indicate "if this algorithm is being run as part of a larger algorithm" (for example if a given algorithm is part of an algorithm which calls other Processing
algorithms).
Internally this seems to mostly impact the way the ownership of the layers created by the algorithm is transferred (or not) to the caller.
In your case it seems that leaving this value on False
is the right solution.
Explore related questions
See similar questions with these tags.
is_child_algorithm=False
results in the outputs becomingQgsVectorLayer
objects while otherwise one gets a string (as reference to a layer in the project or whatever?).