Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    subprocess not running in background

    Cinema 4D SDK
    python 2023 macos
    2
    4
    757
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bee7er
      last edited by

      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

      py-srs_test.zip

      1 Reply Last reply Reply Quote 0
      • B
        bee7er
        last edited by

        A test project is supplied in the 'projects' folder. Use that when testing.

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @bee7er
          last edited by ferdinand

          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.

          1. 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
          1. 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.
          2. 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

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 1
          • B
            bee7er
            last edited by

            MAny thanks Ferdinand. I will look into the BatchRender suggestion. That looks promising.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post