Reputation: 1128
I am using a client server architechture, and the client side is on the blender.
Since, client has to infinitely wait for the text from server, I have used an infinite while loop. But, Blender freezes the moment I run the script, it doesn't show anything happening in each step, and when I end the execution manually using command line, it just shows the last step executed.
The script works perfectly if run outside blender. I am using Blender 2.74 on ubuntu.
Any suggestions?
Thanks
Upvotes: 1
Views: 1783
Reputation: 162164
The problem you're running into is a standard issue with every event based, interactive application: Input events and displaying their response happens in a application main event loop, where the gist is about
while(running) {
event = poll_event()
if( event ) {
dispatch_event(event)
}
redraw_window()
}
Now when you execute a script in Blender, this happens somewhere "within" the dispatch_event()
call chain in response to some event, for example you clicking a UI button or hitting the run script hotkey, or by simply a Blender executing your script because it's been registered as a hook to something.
At long as your loop is running, down in dispatch_event()
, the execution of the main application loop is stalled, freezing the rest of the program.
So what can you do about this: Either don't implement such an inner server loop in your program, but use the framework's method to register a new event and piggyback on the existing event loop (in Blender this is called a "modal operator". Or, in your case probably the preferred thing, create a thread for your server to run in concurrently to the main event loop.
Also see https://www.blender.org/api/blender_python_api_2_76_1/info_gotcha.html#can-i-redraw-during-the-script which is relevent in your case.
Upvotes: 2