wip multithreading

perf-debug
nyanpasu64 2023-11-27 11:28:27 -08:00
rodzic 728e775ca0
commit eb612a54fe
4 zmienionych plików z 30 dodań i 6 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ from typing import Optional, List, Tuple, Union, cast, TypeVar
import click
import corrscope
import corrscope.settings.global_prefs as gp
from corrscope.channel import ChannelConfig
from corrscope.config import yaml
from corrscope.corrscope import template_config, CorrScope, Config, Arguments
@ -79,6 +80,7 @@ def get_file_stem(cfg_path: Optional[Path], cfg: Config, default: T) -> Union[st
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
# fmt: off
@click.command(context_settings=CONTEXT_SETTINGS)
# Inputs
@ -232,7 +234,13 @@ def main(
outputs.append(cfg.get_ffmpeg_cfg(video_path))
if outputs:
arg = Arguments(cfg_dir=cfg_dir, outputs=outputs)
try:
pref = gp.load_prefs()
except Exception as e:
print(e)
pref = gp.GlobalPrefs()
arg = Arguments(cfg_dir=cfg_dir, outputs=outputs, parallel=pref.parallel)
command = lambda: CorrScope(cfg, arg).play()
if profile:
first_song_name = Path(files[0]).name

Wyświetl plik

@ -6,6 +6,7 @@ from enum import unique
from fractions import Fraction
from pathlib import Path
from typing import Iterator, Optional, List, Callable
from multiprocessing.pool import Pool
import attr
@ -148,6 +149,7 @@ IsAborted = Callable[[], bool]
class Arguments:
cfg_dir: str
outputs: List[outputs_.IOutputConfig]
parallel: bool = False
on_begin: BeginFunc = lambda begin_time, end_time: None
progress: ProgressFunc = lambda p: print(p, flush=True)
@ -268,7 +270,8 @@ class CorrScope:
benchmark_mode = self.cfg.benchmark_mode
not_benchmarking = not benchmark_mode
with self._load_outputs():
def play_impl():
nonlocal end_frame
prev = -1
# When subsampling FPS, render frames from the future to alleviate lag.
@ -339,6 +342,12 @@ class CorrScope:
end_frame = frame + 1
break
with self._load_outputs():
if self.arg.parallel:
pass
else:
play_impl()
if PRINT_TIMESTAMP:
# noinspection PyUnboundLocalVariable
dtime_sec = time.perf_counter() - begin

Wyświetl plik

@ -185,8 +185,6 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
prefs_error = None
try:
self.pref = gp.load_prefs()
if not isinstance(self.pref, gp.GlobalPrefs):
raise TypeError(f"prefs.yaml contains wrong type {type(self.pref)}")
except Exception as e:
prefs_error = e
self.pref = gp.GlobalPrefs()
@ -608,7 +606,10 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
)
arg = Arguments(
cfg_dir=self.cfg_dir, outputs=outputs, is_aborted=raise_exception
cfg_dir=self.cfg_dir,
outputs=outputs,
parallel=self.pref.parallel,
is_aborted=raise_exception,
)
return arg

Wyświetl plik

@ -40,13 +40,19 @@ class GlobalPrefs(DumpableAttrs, always_dump="*"):
else:
return self.file_dir_ref
parallel: bool = True
_PREF_PATH = paths.appdata_dir / "prefs.yaml"
def load_prefs() -> GlobalPrefs:
try:
return yaml.load(_PREF_PATH)
pref = yaml.load(_PREF_PATH)
if not isinstance(pref, GlobalPrefs):
raise TypeError(f"prefs.yaml contains wrong type {type(pref)}")
return pref
except FileNotFoundError:
return GlobalPrefs()