very interesting. this is the first time i've heard someone on a different platform talk about focus stealing during script execution. this happens to me all the time on osx-86 and because i use spaces (virtual desktops), when PI starts doing this, i can't use my computer at all anymore.
my guess is this is some kind of QT bug, though for me it seemed to correlate with when the pixinsight console window activated itself as the script iterates.