SofaPython3 icon indicating copy to clipboard operation
SofaPython3 copied to clipboard

Handling python exceptions

Open jnbrunet opened this issue 4 years ago • 0 comments

The discussion started in #92 .

The following scene will behave differently either we are using SofaPython(2) or SofaPython3:

Test scene

# test.py
def createScene(root)
    root = '2' + 2

Using SofaPython(2):

[ERROR]   [PythonScript] TypeError: cannot concatenate 'str' and 'int' objects
  File "test.py", line 2, in createScene
    root = '2' + 2

Using SofaPython3:

[ERROR]   [SofaPython3::SceneLoader] TypeError: can only concatenate str (not "int") to str

At:
  test.py(2): createScene

In order to have the same behavior, we would have to place an exception hook in python interpreter of the plugin SofaPython3. However, this was not possible before python 3.8:

@damienmarchal in #92 I think there is two issue mixed together. One is about the exception risen from python. In SofaPython they were catched by a dedicated hook installed by Sofa in the python interpreter. Because of multithreading this feature was broken before 3.8 and thus SofPython3 was not using it. The consequence is that when there is an error at the python level the behavior is different.

jnbrunet avatar Jan 26 '21 14:01 jnbrunet