I am using command-line to execute a C4D script through c4dpy.exe. I want to close c4dpy after the script execution completes. How can I do this?
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--args', type=str, help='argument to be passed')
    args = parser.parse_args()
    if args.args:
        print(f'Received argument: {args.args}')      
    # quit c4d?
    c4d.CallCommand(12104)
In addition, I am rendering a octane scene in this script, but sometimes the rendering process keeps running and it is unclear whether it is a bug in c4dpy or if I am using c4dpy incorrectly.
import c4d 
import os
class RenderAgent:
    def __init__(self):
        self.progress = 0
        
    def render(self, doc, save_path=None, thread=None):
        self.progress = 0
        rd = doc.GetActiveRenderData()
        rd[c4d.RDATA_ALPHACHANNEL] = 1
        bmp = c4d.bitmaps.MultipassBitmap(int(rd[c4d.RDATA_XRES]), int(rd[c4d.RDATA_YRES]), c4d.COLORMODE_RGB)
        bmp.AddChannel(True, True)
        # Renders the document
        if thread:
            thread = thread.Get()
        
        if c4d.documents.RenderDocument(doc, rd.GetData(), bmp, c4d.RENDERFLAGS_EXTERNAL, thread, prog=self.PythonCallBack, wprog=self.PythonWriteCallBack) != c4d.RENDERRESULT_OK:
            #print("Failed to render the temporary document.")
            return False
        if save_path:
            bmp.Save(save_path, c4d.FILTER_PNG, data=None, savebits=c4d.SAVEBIT_ALPHA)
        return bmp
    def PythonCallBack(self, progress, progress_type):
        self.progress = float(int(progress*100))
        if self.progress>100:
            self.progress = 100
        print(self.progress)
        # !!
        # When i print self.progress  inside octane renderer scene (Actually, I am using a logging module. It can redirect the print output to an external log.txt file.)
        # it will still return 0 after it return 100 
        # It seems that the renderer has entered an infinite loop.
    def PythonWriteCallBack(self, mode, bmp, fn, mainImage, frame, renderTime, streamnum, streamname):
        ...
# call this in c4dpy
# simple code
RA = RenderAgent()
save_path = r"..."
RA.render(doc, save_path)
my log file  looks like this:
LEVEL:1 - 2023-05-06 16:10:23
rendering start
LEVEL:1 - 2023-05-06 16:10:23
rendering:0.0
# ... (rendering
LEVEL:1 - 2023-05-06 16:10:23
rendering:100.0  # it seems like render finished but
LEVEL:1 - 2023-05-06 16:10:23
rendering:0.0
LEVEL:1 - 2023-05-06 16:10:23
rendering:0.0
... 
# (it keeps output 0.0