0
$\begingroup$

I've built Blender as a bpy-only module meaning I can call it directly from Python. I was able to run some commands, but at the moment is failing with simply opening a main file.

My code is super simple:

@app.route('/')
def hello():
   bpy.context.scene.render.engine = 'CYCLES' 
   bpy.ops.wm.open_mainfile(filepath='/home/yuranos/development/3D/model_all_parts.blend')

And yet I'm failing when trying to open my file:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

The interesting bit is that the same python version with the same bpy-related code runs perfectly well from console. I'm new to Python and don't understand if it's a problem with the way I use bpy from Flask or with bpy itself.

$\endgroup$
8
  • $\begingroup$ You cannot just run bpy outside of Blender, it's an API. It needs to run in Blender. You can start Blender, open a file and run a script. This might be helpfull: blender.stackexchange.com/questions/1365/… $\endgroup$ – Martynas Žiemys May 21 '20 at 8:20
  • $\begingroup$ Also see this: docs.blender.org/manual/en/latest/advanced/command_line/… $\endgroup$ – Martynas Žiemys May 21 '20 at 8:22
  • $\begingroup$ You'd be surprised, @MartynasŽiemys, but you definitely can. And if you read my question till the end you'd see that I do run it in bash console as bpy module. You just need to compile the module manually, which is what I did. And it actually works for some commands, but fails for others. $\endgroup$ – yuranos May 21 '20 at 17:20
  • $\begingroup$ Also see: blender.stackexchange.com/questions/117200/… $\endgroup$ – yuranos May 21 '20 at 17:22
  • 1
    $\begingroup$ IMO Could be made clearer in question. Picked it as bpy module re your previous question (have same issue re draco) An observation, setting scene render to cycles then opening mainfile will set render to whatever the context is of the new file's context scene won't it?. $\endgroup$ – batFINGER May 21 '20 at 17:58
0
$\begingroup$

Haven't done much with flask, will offer this up as a suggested workaround.

Try loading the mainfile outside of @route decorated methods.

Putting the load operator in any route method also caused a segfault for me (Ubuntu 18, blender 2.90, python 3.82) Suspect a threading issue.

The following works as expected,

# batTOOLS...........

from flask import Flask
import bpy

app = Flask(__name__)
bpy.ops.wm.open_mainfile(filepath="/home/batfinger/Documents/blender/tests/BISECTO.blend")


@app.route('/')
def hello_world():
    lines = []
    for o in bpy.data.objects:
        lines.append(f"{o.name}</br>")

    return "\n".join(lines)
$\endgroup$
1
  • $\begingroup$ It does work, but I'm still to figure out if it's about threading or something else. We tried to disable threading(devtalk.blender.org/t/…) and in itself it's not enough because there's another strange thing: code with app.run(threaded=False) runs Ok when I start the app as: python3.7 app.py, but it fails when I run it as: flask run. I'm new to both Python and Flask, been a JVM fun boy for a decade, so will need to research. $\endgroup$ – yuranos May 22 '20 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.