(Python 3.11) I was trying to read a Blender file in Gradio, but something weird happened that I can't understand. Here is a simplified version of the problem I met today: When I try to run this code in gradio, I got error:
import gradio as gr
import bpy
blend_filepath = "/root/shiki/testp.blend"
## bpy.ops.wm.open_mainfile(filepath=blend_filepath)
def read():
bpy.ops.wm.open_mainfile(filepath=blend_filepath)
fps = str(bpy.context.scene.render.fps)
res = str(bpy.context.scene.render.resolution_x) + "*" + str(bpy.context.scene.render.resolution_y)
info = "FrameRate: " + fps + "\n" + "Resolution: " + res
return info
with gr.Blocks() as demo:
read_blend_file = gr.Button("Read Your Blender File")
file_info_box = gr.Textbox(label="File Info")
read_blend_file.click(fn=read, outputs=file_info_box)
demo.launch()
What made me confused is that, if I simply move bpy.ops.wm.open_mainfile(filepath=blend_filepath) out of function that triggered by Gradio button, the problem disappears. Does it means there's a conflict between Gradio and bpy?
import gradio as gr
import bpy
blend_filepath = "/root/shiki/testp.blend"
bpy.ops.wm.open_mainfile(filepath=blend_filepath)
def read():
## bpy.ops.wm.open_mainfile(filepath=blend_filepath)
fps = str(bpy.context.scene.render.fps)
res = str(bpy.context.scene.render.resolution_x) + "*" + str(bpy.context.scene.render.resolution_y)
info = "FrameRate: " + fps + "\n" + "Resolution: " + res
return info
with gr.Blocks() as demo:
read_blend_file = gr.Button("Read Your Blender File")
file_info_box = gr.Textbox(label="File Info")
read_blend_file.click(fn=read, outputs=file_info_box)
demo.launch()
About crash logs: In Linux (bpy as python3.11 module):
root@mypc:~/shiki# python test.py
* Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Read blend: "/root/shiki/testp.blend"
Segmentation fault (core dumped)
No crash file generated in this case.
In Windows (run test.py in blender):
* Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Read blend: "C:\Users\Shiki\Desktop\TmpRender\tst.blend"
Error: EXCEPTION_ACCESS_VIOLATION
Address: 0x00007FF75E9C9270
Module: blender.exe
Thread: 0004e28c
Writing: C:\Users\Shiki\AppData\Local\Temp\script.crash.txt