@datamilch said in Calling BaseDocument.SetMode twice in a row leads to freezes:
always had the feeling, that i could print feedback while it is running
That is a misconception many users have. This is because most code usually runs very fast, so you do not realize it. Note that I also wrote Script Manager script. While it technically applies to all Python Scripting scene elements, the execution of the Python VM is there always blocking, it is much more prominent for a Script Manager script. Because there the module is only executed once and it is also okay to run scripts here which take seconds to execute. But it also applies for example to a Python Programming tag, the execution of the module is there also blocking. But because the module of a Python Programming tag is called many times - on each scene update at least once, and you are anyway in a world of hurt when your Python Programming tag module takes more than ~100 ms to run, it is not that obvious there.
Syntax errors are evaluated before the VM actually runs because then the compilation of your code into byte code fails (which is then later interpreted by the VM). But the error is here also displayed only after the VM stopped (just as a RuntimeError which is raised by the VM and not by the compiler), but syntax errors prevent the VM from running your code in the first place.
Cheers,
Ferdinand
import time
def main() -> None:
"""Run as a Python Script Manager script to see that the execution of a scope in the Python
VM is blocking. This will not print five 'A's with a stride of one second, but five 'A's after
five seconds.
"""
for _ in range(5):
print('A')
time. Sleep(1)
if __name__ == '__main__':
main()