3
$\begingroup$

I am making an addon to launch background rendering in GUI. I want to use subprocess.Popen to execute blender with -b. And here is my code:

import bpy
import subprocess
import multiprocessing

FILE = "test.blend"

class Background_Render(bpy.types.Operator):
    """call blender in background"""
    bl_idname = "render.back_render"
    bl_label = "Render in Background"

    def execute(self, context):
        #render_task()
        task = multiprocessing.Process(target=self.render_task, args=(context, ))
        task.start()
        return {"FINISHED"}

    def render_task(self, context):
        argument = ['blender', '-b', FILE, '-f', '1']
        process_handle = subprocess.Popen(
            argument,
            stdout = subprocess.PIPE,
            stderr=subprocess.STDOUT
        )
        for line in iter(process_handle.stdout.readline, b''):
            print(line.rstrip().decode()) # print for debug
            # both below not work
            context.area.header_text_set(line.rstrip().decode()) # show info in GUI
        context.area.header_text_set() # set empty after finish

My first approach is run Popen or say render_task directly, however blender will freeze when I start the job. So I commented it away. And I added the call to a multiprocessing.Process. It not get freezed. Unfortunately, string can be print into terminal but not into GUI with context.area.header_text_set or Operator.report.

What is the best practice to show data in multiprocess? And why they are not showing?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Inter process communication solutions between Blender 's window manager and event system and another process are tricky at best: not impossible, quite possible, but requires extra effort.

ideasman42 has an excellent solution presented at blender.stackexchange.com/q/45731/228

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .