0
$\begingroup$

I am trying to parallelize rendering using blender's python API, built as a python module. I'd like to use multiple instances of blender contained within their own classes. Currently, I can generate multiple instances by running a script multiple times, but cannot have two functioning instances of the class in the same script, due to how bpy uses import to initialize the blender instance. Is there a way to get around this? A cut down version of the class is below.

class BpyRenderer(object):
    import bpy
    def __init__(self):
        self.bpy.ops.wm.open_mainfile(filepath='blank.blend')
    def render(self, filename):
        self.bpy.data.scenes['Scene'].render.filepath = filename
        self.bpy.ops.render.render( write_still=True )
$\endgroup$
  • $\begingroup$ Have you already tried with threads? $\endgroup$ – yhoyo Aug 8 '18 at 1:47
  • $\begingroup$ One thread works, two conflict and the second one works but the first fails. I tested it with each thread object importing the BpyRenderer and loading a model. $\endgroup$ – bokorn Aug 8 '18 at 15:49
1
$\begingroup$

Blender only allows one render to run in each instance. As a single render instance will normally use all available cpu's there isn't usually any benefit to running multiple renders at the same time.

If you do want to run multiple renders at the same time, you will either need to run multiple instances of your script or of blender.

$\endgroup$
  • $\begingroup$ I want multiple instances of blender because the choke point is in loading the models for my problem, and I want some instances loading while others are rendering. I can have each one run independently and communicate over sockets, but was wondering if there was a cleaner. $\endgroup$ – bokorn Aug 8 '18 at 15:56
  • $\begingroup$ Running multiple renders at once would all work from the same scene and model data, so you don't want them all running from the same scene, you actually want to start a new process for each model. $\endgroup$ – sambler Aug 8 '18 at 19:32
  • $\begingroup$ Yes, is there a way of doing that without running multiple instances of a python interpreter i.e. making bpy generate another instance of blender? $\endgroup$ – bokorn Aug 8 '18 at 22: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.