Redirect internal Python errors sometimes doesn't work

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Redirect internal Python errors sometimes doesn't work

Postby triplus » Wed Mar 30, 2016 2:31 pm

I noticed something and i can't be 100% sure about what is going on. It seems that if FreeCAD config files (system.cfg and user.cfg) are deleted and FreeCAD is restarted (current master) sometimes internal Python errors aren't redirected to report view.

I notice this occasionally when working on TabBar. What helps it to open Preferences ... -> Output window (this step might not be needed) -> Apply/OK. After FreeCAD is restarted redirecting of potential Python errors introduced on the FreeCAD Python module level works again as expected!
User avatar
bejant
Posts: 6076
Joined: Thu Jul 11, 2013 3:06 pm

Re: Redirect internal Python errors sometimes doesn't work

Postby bejant » Thu Mar 31, 2016 2:19 am

triplus wrote: It seems that if FreeCAD config files (system.cfg and user.cfg) are deleted and FreeCAD is restarted (current master) sometimes internal Python errors aren't redirected to report view.
Maybe I'm missing something, but if those two files are deleted I'd expect that neither internal Python output or errors are redirected to the Report View. IIRC the default settings for both Preferences is False, but I haven't changed them for so long that I could be wrong....
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: Redirect internal Python errors sometimes doesn't work

Postby triplus » Thu Mar 31, 2016 10:30 am

bejant wrote:IIRC the default settings for both Preferences is False, but I haven't changed them for so long that I could be wrong....
This changed as now by default they are set to on.

P.S. I tried to provide code snippet to put in InitGui.py and test it but it looks like when doing just that (using only the snippet in InitGui.py) redirect works fine after. Therefore i think that best to leave it as it is for now and if i or somebody else can isolate the code to reliably reproduce the behaviour in the future more can be done about understanding what is going on.
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: Redirect internal Python errors sometimes doesn't work

Postby triplus » Mon Aug 08, 2016 2:41 pm

Delete (or rename) user.cfg file and after create test InitGui.py file in Mod directory (on Linux .FreeCAD/Mod/test/InitGui.py). In it put this single line:

Code: Select all

print "Test"
No output should be visible in Report view panel once FreeCAD starts. If Edit -> Preferences... is selected and the Preferences dialog is after closed by pressing on the OK button the next time FreeCAD is started Report view panel should have Test printed in it. The reason it works like this is when enabling redirects by default:

issue #2454

No additional check was added to check the parameters at FreeCAD start. Therefore only when opening Preferences dialog for the first time this will get done. If instead i do that manually:

Code: Select all

paramGet = App.ParamGet("User parameter:BaseApp/Preferences/OutputWindow")

a = paramGet.GetBool("RedirectPythonOutput", True)
b = paramGet.GetBool("RedirectPythonOutput", False)

if a == b:
    pass
else:
    paramGet.SetBool("RedirectPythonOutput", 1)

c = paramGet.GetBool("RedirectPythonErrors", True)
d = paramGet.GetBool("RedirectPythonErrors", False)

if c == d:
    pass
else:
    paramGet.SetBool("RedirectPythonErrors", 1)

print "Test"
After Test will always be printed to Report view panel (unless this option is disabled in Preferences dialog) regardless of the fact if Preferences dialog was opened for the first time or not. And there are a few more parameters found in OutputWindow group that behave in the same way.
triplus
Posts: 9464
Joined: Mon Dec 12, 2011 4:45 pm

Re: Redirect internal Python errors sometimes doesn't work

Postby triplus » Wed Oct 05, 2016 5:04 pm