When I run this command:
manim_command = f'sudo docker run --rm -v {base_dir}/manim/python_code_files:/mnt/code -v {base_dir}/media:/mnt/output manim-image manim -ql /mnt/code/user_code.py -o /mnt/output/{class_name}'
using subprocess.run or subprocess.Popen or os.system, It successfully runs(create an image or video file), but it blocks the terminal and prevents the further rendering of the template.
If the file is already present, it will successfully display it. But if the file is not present, it will render but not show.
I have tried running the docker container in detached mode, but that just renders the template before creating the file.obviously we have to wait till the process is over:
while True: if check_file_exists(class_name): break time.sleep(2) print('File created')
so, it waits till the file is created, but when I add this block, it waits for the the file to be created, prints 'File created' and then gets stuck just before rendering the template.
why doesn't it render?
try: # Run the function run_manim_command(class_name) print('function completed') except Exception as e: result_message = f"Error executing shell command: {e}" #after POST request context = {'previous_code': previous_code,'MEDIA_URL': settings.MEDIA_URL,'class_name':class_name,'placeholder': False, } return render(request, 'run.html',context)
It even prints 'function completed'
I have tried:
- using thread to run as an asynchronous process but the same result as with running in detached mode
- stopping and removing the container. It seems that the container is already stopped because I have used --rm. so, what is blocking?
- killing the subprocess with process.kill() and process.terminate(). These commands ran without error, but did not unblock the terminal.
- running with os.system instead of subprocess.
I am running subprocess with shell = True, it won't work without that.