subprocess not running in background
-
I am writing a C4D Python plugin to render one or more frames. I am using the 2023 C4D, which uses Python 3. The plugin is working just fine and I can invoke a Python script, which calls a shell script to run the C4D Commandline passing various parameters. All this works fine and the frame images are rendered correctly, except that while the render is running I am unable to continue editing in C4D because the render is running in the foreground thread.
I think the subprocess.run function I am using which submits a Python script to manage the shell script should run in the background allowing me to continue editing my project.
To recreate the problem unzip the attached plugin into the plugins folder. Check the PYTHON_INTERPRETER and COMMANDLINE_EXECUTABLE symbolic constants in the py-srs_test.pyp script to make sure they are correctly set. Then run the plugin and click the OK button in the dialog which pops up. The render will run for about 10 or 15 seconds during which time you will be unable to edit the project.
Thanks
-
A test project is supplied in the 'projects' folder. Use that when testing.
-
Hello @bee7er,
Thank you for reaching out to us. You cannot run multiple instances of c4dpy or the command line in parallel. Primarily because you lack the licenses to do so (each instance requires its own license), and secondly in the case of c4dpy also because we do not support things like
multiprocessing
with our Python VM.To do what you seem to want to do, carry out a distributed rendering, you have three options.
- Use c4d.documents.BatchRender: This is probably the most straight forward route and there are multiple subjects on the forum and GitHub dealing with the fundamentals and corner cases of this task, as for example:
- The BatchRender section on GitHub.
- Adding multiple cameras from a single file to the render queue
- How to change render setting before add BatchRender
- Use c4d.documents.RenderDocument: Renderings are by design threaded, so when ever you spawn a rendering, it will run in its own thread(s). But calling this function is not, so you would have to wrap each
RenderDocument
job in its own C4DThread, so that fetching the results can then be tied together in the main thread. - Use the net, i.e. Teams render module. This is by far the most complex solution.
Finally, rendering these days is increasingly happening on the GPU with render engines trying to allocate most or all VRAM of your GPU ahead of time. Spawning multiple instances of a renderer is in these cases very counter-productive as they then fight each other for the VRAM. In the case of GPU renderers a singular rendering is often already as much parallelization as your hardware can muster.
Cheers,
Ferdinand -
MAny thanks Ferdinand. I will look into the BatchRender suggestion. That looks promising.