How to flush the App.Console?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

How to flush the App.Console?

Post by microelly2 »

I want to get some information about a long time running operation.
When I run the script, I can notice the the breaks in the shell-window but not in the report view window of the freecad app.
Is it possibly tho flush then App.Console.

Code: Select all

def say(wort):
	App.Console.PrintMessage(str(wort) + "\n")
#	App.Console.flush()   ???


import time
import datetime


# main
say("hallo")

say(str(datetime.datetime.now()))
start = time.time() 
time.sleep(0.05)
say("pause run")
time.sleep(1.05)
ende = time.time() 
say(str(datetime.datetime.now()))
say(start)
say(ende)
say('script was runnnig ${0:.3f}'.format(ende-start))
OS: "openSUSE 12.1 (x86_64)"
Platform: 64-bit
Version: 0.13.1830 (Git)
Branch: releases/FreeCAD-0-13
Hash: ec7636d7aaf2612e9b43cff5d6a424037d53e505
Python version: 2.7.2
Qt version: 4.7.4
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.5.0
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to flush the App.Console?

Post by wmayer »

The reason is that for a long running operation the event loop is blocked and thus messages that should be printed to the report window cannot be processed but are kept in an event queue. After the operation has finished the event loop gets executed again and processes the events in the queue.

So, there are two ways to solve this:
1. In FreeCAD we have FreeCADGui.updateGui() which forces the event loop to process all events in the queue
2. To avoid to block the event loop you can move the long running operation into a thread
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How to flush the App.Console?

Post by microelly2 »

thank you,
now it works like expected. so I can start to explode compound objects.
Post Reply