Prevent subprocesses from constantly opening windows on Windows (#109)

* Add subprocess.CREATE_NO_WINDOW to blender_engine.py

* Convert ffmpeg_engine.py to use CREATE_NO_WINDOW

* Cleanup Blender implementation

* Cleanup subprocesses in base_worker.py

* Cleanup subprocesses in base_engine.py

* Fix main.spec for Windows (optimize=2 broke it)
This commit is contained in:
2024-08-13 22:16:03 -05:00
committed by GitHub
parent d30978bef0
commit 81e79a1996
5 changed files with 30 additions and 19 deletions

View File

@@ -6,6 +6,8 @@ from src.utilities.misc_helper import system_safe_path
logger = logging.getLogger()
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
class Blender(BaseRenderEngine):
@@ -35,7 +37,8 @@ class Blender(BaseRenderEngine):
try:
render_path = self.renderer_path()
if render_path:
ver_out = subprocess.check_output([render_path, '-v'], timeout=SUBPROCESS_TIMEOUT)
ver_out = subprocess.check_output([render_path, '-v'], timeout=SUBPROCESS_TIMEOUT,
creationflags=_creationflags)
version = ver_out.decode('utf-8').splitlines()[0].replace('Blender', '').strip()
except Exception as e:
logger.error(f'Failed to get Blender version: {e}')
@@ -50,7 +53,7 @@ class Blender(BaseRenderEngine):
if os.path.exists(project_path):
try:
return subprocess.run([self.renderer_path(), '-b', project_path, '--python-expr', python_expression],
capture_output=True, timeout=timeout)
capture_output=True, timeout=timeout, creationflags=_creationflags)
except Exception as e:
logger.error(f"Error running python expression in blender: {e}")
else:
@@ -67,7 +70,7 @@ class Blender(BaseRenderEngine):
command = [self.renderer_path(), '-b', '--python', script_path]
if project_path:
command.insert(2, project_path)
return subprocess.run(command, capture_output=True, timeout=timeout)
return subprocess.run(command, capture_output=True, timeout=timeout, creationflags=_creationflags)
except Exception as e:
logger.exception(f"Error running python script in blender: {e}")
@@ -116,7 +119,7 @@ class Blender(BaseRenderEngine):
return None
def get_arguments(self):
help_text = subprocess.check_output([self.renderer_path(), '-h']).decode('utf-8')
help_text = subprocess.check_output([self.renderer_path(), '-h'], creationflags=_creationflags).decode('utf-8')
lines = help_text.splitlines()
options = {}
@@ -164,7 +167,7 @@ class Blender(BaseRenderEngine):
def supported_render_engines(self):
engine_output = subprocess.run([self.renderer_path(), '-E', 'help'], timeout=SUBPROCESS_TIMEOUT,
capture_output=True).stdout.decode('utf-8').strip()
capture_output=True, creationflags=_creationflags).stdout.decode('utf-8').strip()
render_engines = [x.strip() for x in engine_output.split('Blender Engine Listing:')[-1].strip().splitlines()]
return render_engines