Fix terminating previews

perf-debug
nyanpasu64 2023-11-27 15:26:10 -08:00
rodzic 37a1d69058
commit 34b64d3cc6
1 zmienionych plików z 20 dodań i 4 usunięć

Wyświetl plik

@ -7,7 +7,7 @@ from contextlib import ExitStack, contextmanager
from enum import unique from enum import unique
from fractions import Fraction from fractions import Fraction
from pathlib import Path from pathlib import Path
from queue import Queue from queue import Queue, Empty
from threading import Thread from threading import Thread
from typing import Iterator, Optional, List, Callable, Tuple from typing import Iterator, Optional, List, Callable, Tuple
@ -390,9 +390,6 @@ class CorrScope:
# Only count output-displayed frames, not rendered. # Only count output-displayed frames, not rendered.
# # Used for FPS calculation # # Used for FPS calculation
# thread_shared.end_frame = frame # thread_shared.end_frame = frame
for output in self.outputs:
output.terminate()
break break
time_seconds = frame / fps time_seconds = frame / fps
@ -441,6 +438,7 @@ class CorrScope:
) )
render_to_output.put(None) render_to_output.put(None)
print("exit render")
global worker_render_frame # hack to allow pickling function global worker_render_frame # hack to allow pickling function
@ -455,6 +453,11 @@ class CorrScope:
def output_thread(): def output_thread():
while True: while True:
if is_aborted():
for output in self.outputs:
output.terminate()
break
msg = render_to_output.get() # blocking msg = render_to_output.get() # blocking
if msg is None: if msg is None:
break break
@ -472,6 +475,19 @@ class CorrScope:
thread_shared.end_frame = frame + 1 thread_shared.end_frame = frame + 1
break break
if is_aborted():
# If is_aborted() is True but render_thread() is blocked on
# render_to_output.put(), then we need to clear the queue so
# render_thread() can return from put(), then check is_aborted()
# = True and terminate.
while True:
try:
render_to_output.get(block=False)
except Empty:
break
print("exit output")
with ProcessPoolExecutor( with ProcessPoolExecutor(
ncores, initializer=worker_create_renderer, initargs=(renderer,) ncores, initializer=worker_create_renderer, initargs=(renderer,)
) as pool: ) as pool: