Why do infinite loops in the command line block the editor's UI?

I’m using the Python plugin, and by writing an infinite loop (like below) in the console the Unreal Editor UI will block.

The Python code with the loop is just:

while True:
    print(0)

In fact, what I was trying to do was running a Python web server, this is just a simplified version of the same problem.

So my questions are:

  • Why does this happen?
  • Is having an embedded Python web server a decent idea? What I’ll want to do is manipulating the scene (changing textures, etc) through REST endpoints, so that I can eventually use scene capture components to get screenshots.
  • What alternatives do you suggest?

It blocks because its running on the same thread as the UI and hence it cant never get out of the loop to continue executing stuff. This is what you generally want to use the Tick function call, which would kind of work in the same way but without blocking the thread, as it will get called only once per tick for that object. I’m not sure how you would go about doing it on python because I have not used it, but you should look around for a non blocking way of looping (maybe loop certain amount of times per tick or something of the sort). That kind of loop will not fly no matter where you put it in game code unless its a dedicated thread (still you will need a way to break the loop somehow, so as is it would not work there either).