I had a similar need for this functionality a few months ago. My implementation involved making a copy of the automatically generated Python 2.7 file, then editing it to add the desired functionality. In my case I needed a quick and simple way to generate multiple channels and setting variables when executing the file. This was accomplished through the use of the click module, which allowed for setting variables and executing the file via a terminal window.
If you are trying to dynamically calculate and change variables during execution, my suggestion would be to create a separate thread in the main()
function using the threading module (or equivalent). This new thread should call a separate function that loops through your piece of code. Inside this function your algorithm should make use of the variablename_get
and variablename_set
functions that have also been automatically generated by GRC.
It is unclear where the data you are using to calculate these changes in gain comes from, but hopefully this answer is helpful.