Changing threshold values after x samples are collected

Hello everyone.

I have a script that does energy detection based on a threshold.

Right now, I have an array of thresholds I want to test on a small step.
All the values resulting from this may go into the same file, since I
will later work them with MatLab. My question is, is there some kind of
a callback I can define, some kind of variable I can pull from C++ in
Python that tells me x samples have gone through the file sink, causing
a variable change in the block?

As in, the script runs through threshold values 44 to 50 in a 0.01 step
and writes 10000 conclusions (1 or 0) to a file for each step. Is that
doable? Is there an example on how to do this, or any kind of python
clue you could give me?

If this is obvious and easy, I’m sorry, I haven’t been able to find a
solution. I’ve tried gr.head() but I don’t know how to pull its done==1
and
finish the script based on it. (Since I think it must be inside the
init and not the main, and I don’t know how to do things after
events inside init; it seems to just instance stuff to later be run)

Any help would be appreciated, anything else I should study as well.
Thanks in advance,

Miguel.