Porting to python3

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

Yorik wrote:Certainly in Draft I never relied on the order of dict elements I think.
There was only the issue with the snapping/tracking icons. But I think there the order is quite important or not?


Little reminder: python3-branch compiled with python2 has now some problems with the extensions...

Code: Select all

#0  0x00007ffff670ae9a in App::ExtensionContainerPy::getCustomAttributes (this=0x4287380, attr=0x7fffc103b054 "addObject") from /home/lo/anaconda/envs/fc_py2/bin/../lib/libFreeCADApp.so
#1  0x00007ffff670a878 in App::ExtensionContainerPy::_getattr (this=0x4287380, attr=0x7fffc103b054 "addObject") from /home/lo/anaconda/envs/fc_py2/bin/../lib/libFreeCADApp.so
#2  0x00007ffff6715d31 in App::DocumentObjectPy::_getattr (this=0x4287380, attr=0x7fffc103b054 "addObject") from /home/lo/anaconda/envs/fc_py2/bin/../lib/libFreeCADApp.so
#3  0x00007ffff675e401 in App::PartPy::_getattr (this=0x4287380, attr=0x7fffc103b054 "addObject") from /home/lo/anaconda/envs/fc_py2/bin/../lib/libFreeCADApp.so
#4  0x00007ffff5f93c19 in Base::PyObjectBase::__getattr (obj=0x4287388, attr=0x7fffc103b054 "addObject") from /home/lo/anaconda/envs/fc_py2/bin/../lib/libFreeCADBase.so
#5  0x00007ffff5b0ab5b in PyEval_EvalFrameEx (f=f@entry=0x7fffb0021560, throwflag=throwflag@entry=0) at Python/ceval.c:2541
#6  0x00007ffff5b0f99d in PyEval_EvalCodeEx (co=co@entry=0x7fffe6ac7db0, globals=globals@entry=0x7ffff7f58168, locals=locals@entry=0x7ffff7f58168, args=args@entry=0x0, argcount=argcount@entry=0, 
    kws=kws@entry=0x0, kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, closure=closure@entry=0x0) at Python/ceval.c:3582
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

Finally a python3-conda-package to test freecad with python3:
Instructions to install the package are on top of the python3-wiki: https://www.freecadweb.org/wiki/Python_3
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

Maybe someone knows what this means. Creating a Bspline with sketcher in python3 doesn't work. (On right click for finishing the spline this exception is printed:

Code: Select all

<class 'Part.BSplineCurve'> returned a result with an error set
after closing the mainWindow, a crash occurs:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x35860) [0x7f02badae860]
#1  /home/lo/anaconda/envs/freecad/bin/../lib/libpython3.5m.so.1.0(+0xb49e8) [0x7f02bcbdb9e8]
#2  0x7f02bd1c03e9 in Base::PyObjectBase::~PyObjectBase() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADBase.so+0x71
#3  0x7f02bd161f5a in Base::BaseClassPy::~BaseClassPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADBase.so+0x2a
#4  0x7f02bd1bac2e in Base::PersistencePy::~PersistencePy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADBase.so+0x2a
#5  0x7f02bd9b1c2a in App::PropertyContainerPy::~PropertyContainerPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x2a
#6  0x7f02bd92debe in App::ExtensionContainerPy::~ExtensionContainerPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x36
#7  0x7f02be7bb3a8 in Gui::ViewProviderPy::~ViewProviderPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x2a
#8  0x7f02be7ae826 in Gui::ViewProviderDocumentObjectPy::~ViewProviderDocumentObjectPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x2a
#9  0x7f02be7ae856 in Gui::ViewProviderDocumentObjectPy::~ViewProviderDocumentObjectPy() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x18
#10  0x7f02be49580a in Base::PyObjectBase::PyDestructor(_object*) from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x60
#11  0x7f02be46dbea in Base::PyObjectBase::DecRef() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x50
#12  0x7f02be794346 in Gui::ViewProvider::~ViewProvider() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x54
#13  0x7f02be7aa045 in Gui::ViewProviderDocumentObject::~ViewProviderDocumentObject() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0x89
#14  0x7f02be7b189a in Gui::ViewProviderGeometryObject::~ViewProviderGeometryObject() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADGui.so+0xaa
#15  0x7f02373911a9 in PartGui::ViewProviderPartExt::~ViewProviderPartExt() from /home/lo/anaconda/envs/freecad/lib/./PartGui.so+0x21d
#16  0x7f023738e548 in PartGui::ViewProviderPart::~ViewProviderPart() from /home/lo/anaconda/envs/freecad/lib/./PartGui.so+0x2a
#17  0x7f02373adc2f in PartGui::ViewProvider2DObject::~ViewProvider2DObject() from /home/lo/anaconda/envs/freecad/lib/./PartGui.so+0x97
#18  0x7f024472730c in SketcherGui::ViewProviderSketch::~ViewProviderSketch() from /home/lo/anaconda/envs/freecad/lib/SketcherGui.so+0x174
#19  0x7f0244727348 in SketcherGui::ViewProviderSketch::~ViewProviderSketch() from /home/lo/anaconda/envs/freecad/lib/SketcherGui.so+0x18
#20  0x7f02bd98dc35 in App::Transaction::~Transaction() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0xb9
#21  0x7f02bd98dd04 in App::Transaction::~Transaction() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x18
#22  0x7f02bd8ad067 in App::Document::clearUndos() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x57
#23  0x7f02bd8af080 in App::Document::~Document() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x3a
#24  0x7f02bd8af492 in App::Document::~Document() from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x18
#25  0x7f02bda192a2 in std::default_delete<App::Document>::operator()(App::Document*) const from /home/lo/anaconda/envs/freecad/bin/../lib/libFreeCADApp.so+0x2e
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

Maybe someone knows what this means. Creating a Bspline with sketcher in python3 doesn't work. (On right click for finishing the spline this exception is printed:
When raising an exception in an extension class then this happens in two steps:
1. Set an exception type and text
2. Return with NULL from the callback function

Now two things can go wrong:
1. NULL is returned but an exception isn't set: this leads to a message like "returned NULL without exception set" or so
2. an exception is set but a value different to NULL is returned. This leads to the message "returned a result with an error set"

The question now is where exactly this happens. But according to message it can only be here: https://github.com/FreeCAD/FreeCAD/blob ... ePyImp.cpp
after closing the mainWindow, a crash occurs:
I have seen this too. A fix is coming soon...
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

wmayer wrote:The question now is where exactly this happens. But according to message it can only be here: https://github.com/FreeCAD/FreeCAD/blob ... ePyImp.cpp
I added some tests to TestPartApp.py: https://github.com/looooo/FreeCAD/commi ... 621f9e2fdb
With python3 I get in this line

Code: Select all

Unhandled unknown exception caught in GUIApplication::notify.
Not tested with python2 yet.

@abdullah can you point me to the file where you use the Python functions of this file in the sketcher.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

When creating the spline then only these two functions are invoked:

Code: Select all

BSplineCurvePy::buildFromPoles
and

Code: Select all

BSplineCurvePy::PyInit
Can you check if the latest changes fixes the issue?
git commit 72375db
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

I added some tests to TestPartApp.py: https://github.com/looooo/FreeCAD/commi ... 621f9e2fdb
With python3 I get in this line
Yes, internally an OCC exception is raised but inside setKnot and a few other methods a try/catch is missing to handle the exception. Now the exception is handled in the core system which doesn't know about OCC and thus writes a generic error text.

So, setKnot and co. must be fixed to handle the exception.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

Fixed in git commit 787b930 You must also change the unit test: setKnot(1, ...) because OCC starts always with 1 from counting, not 0.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Porting to python3

Post by looo »

wow, thanks, now sketcher-splines are working with python3
flutefreak7
Posts: 3
Joined: Tue Feb 21, 2017 4:31 pm

Re: Porting to python3

Post by flutefreak7 »

I just wanted to say I'm really excited to see the Python 3 work happening! I've been randomly checking the internet for some of the CAD related tools to be ported to Python 3 ever since I started with Python around 7 years ago and I'm really excited to see all the effort you guys are putting in!

I'm unfortunately not very skilled with C++, but I might could help with translating Python 2 idioms to Python 3 or end user testing or something once I'm more up to speed with FreeCAD. I feel bad just being a needy user and not helping out more, but I do want to say that your work will be appreciated!
Post Reply