How can I verify when a CLIPS subprogram has finished running?

When the Run() function is invoked without arguments, it just returns control to the calling Python program when it has finished running. In most cases this is sufficient, but sometimes it might be useful to divide execution in steps, eg. when the CLIPS subprogram is known to take a long time to finish and there is the need to give some feedback to the user. In this case you can just decide to perform a certain number of steps repeatedly until no rules are fired anymore, as the Run command accepts a "limit" integer argument which must be the maximum number of rules to execute. An example follows:

import clips
while not clips.Run(STEPS) < STEPS:

Run() returns the number of fired rules, so it eventually becomes less than expected (zero if no rules are fired anymore) and this means that the CLIPS subprogram has finished. At any step the calling program can take into consideration the newly activated rules, giving also more granularity to the process.