diff --git a/facefusion/apis/asset_helper.py b/facefusion/apis/asset_helper.py index 5dd8c493..71e22f52 100644 --- a/facefusion/apis/asset_helper.py +++ b/facefusion/apis/asset_helper.py @@ -6,7 +6,7 @@ from typing import List, Optional from starlette.datastructures import UploadFile import facefusion.choices -from facefusion import ffmpeg, process_manager, state_manager +from facefusion import ffmpeg, state_manager from facefusion.face_creator import get_many_faces from facefusion.face_helper import warp_face_by_bounding_box from facefusion.face_selector import sort_faces_by_order @@ -58,8 +58,6 @@ async def save_asset_files(upload_files : List[UploadFile]) -> List[str]: asset_file_name = uuid.uuid4().hex asset_path = os.path.join(temp_path, asset_file_name + file_extension) - process_manager.start() - if media_type == 'audio' and await asyncio.to_thread(ffmpeg.sanitize_audio, upload_file.file, asset_path, api_security_strategy): asset_paths.append(asset_path) @@ -69,8 +67,6 @@ async def save_asset_files(upload_files : List[UploadFile]) -> List[str]: if media_type == 'video' and await asyncio.to_thread(ffmpeg.sanitize_video, upload_file.file, asset_path, api_security_strategy): asset_paths.append(asset_path) - process_manager.end_process() - return asset_paths diff --git a/facefusion/apis/core.py b/facefusion/apis/core.py index a887ad01..2f23b4e8 100644 --- a/facefusion/apis/core.py +++ b/facefusion/apis/core.py @@ -119,5 +119,5 @@ def stop_server(server : uvicorn.Server, signum : int, frame : Optional[FrameTyp if server.should_exit: server.force_exit = True - process_manager.stop_process() + process_manager.stop() server.should_exit = True diff --git a/facefusion/apis/jobs_helper.py b/facefusion/apis/jobs_helper.py index dd8c183f..b13b6fc8 100644 --- a/facefusion/apis/jobs_helper.py +++ b/facefusion/apis/jobs_helper.py @@ -21,5 +21,5 @@ def stop_fork_session() -> None: if fork_id: session_context.set_session_id(fork_id) - process_manager.stop_process() + process_manager.stop() session_context.set_session_id(owner_id) diff --git a/facefusion/benchmarker.py b/facefusion/benchmarker.py index 087ecf92..15c0d859 100644 --- a/facefusion/benchmarker.py +++ b/facefusion/benchmarker.py @@ -6,7 +6,7 @@ from time import perf_counter from typing import Iterator, List import facefusion.choices -from facefusion import content_analyser, core, face_store, process_manager, state_manager +from facefusion import content_analyser, core, face_store, state_manager from facefusion.cli_helper import render_table from facefusion.download import conditional_download, resolve_download_url from facefusion.filesystem import get_file_extension @@ -57,9 +57,7 @@ def cycle(cycle_count : int) -> BenchmarkCycleSet: state_manager.init_item('output_video_fps', detect_video_fps(state_manager.get_item('target_path'))) if state_manager.get_item('benchmark_mode') == 'warm': - process_manager.start() core.conditional_process() - process_manager.end_process() for index in range(cycle_count): if state_manager.get_item('benchmark_mode') == 'cold': @@ -67,11 +65,9 @@ def cycle(cycle_count : int) -> BenchmarkCycleSet: content_analyser.analyse_video.cache_clear() face_store.clear() - process_manager.start() start_time = perf_counter() core.conditional_process() end_time = perf_counter() - process_manager.end_process() process_times.append(end_time - start_time) average_run = round(statistics.mean(process_times), 2) diff --git a/facefusion/core.py b/facefusion/core.py index ecbaf0dd..bb9602e8 100755 --- a/facefusion/core.py +++ b/facefusion/core.py @@ -329,7 +329,6 @@ def process_step(job_id : JobId, step_index : StepIndex, step_args : Args) -> Er try: if common_pre_check() and processors_pre_check(): - process_manager.start() return conditional_process() return 2 @@ -337,7 +336,6 @@ def process_step(job_id : JobId, step_index : StepIndex, step_args : Args) -> Er if process_manager.is_stopping(): logger.info(translator.get('processing_stopped'), __name__) - process_manager.end_process() session_manager.join_session() stores =\ diff --git a/facefusion/download.py b/facefusion/download.py index 162092c5..19d6b322 100644 --- a/facefusion/download.py +++ b/facefusion/download.py @@ -84,7 +84,7 @@ def conditional_download_files(file_set : DownloadSet) -> bool: conditional_download(os.path.dirname(file_path), [ file_url ]) is_valid = conditional_validate_files(file_set) - process_manager.end_process() + process_manager.end() return is_valid diff --git a/facefusion/exit_helper.py b/facefusion/exit_helper.py index f21d92b3..1a37331a 100644 --- a/facefusion/exit_helper.py +++ b/facefusion/exit_helper.py @@ -24,7 +24,7 @@ def signal_exit(signum : int, frame : FrameType) -> NoReturn: def graceful_exit(error_code : ErrorCode) -> NoReturn: signal.signal(signal.SIGINT, signal.SIG_IGN) - process_manager.stop_process() + process_manager.stop() while process_manager.is_processing(): sleep(0.5) diff --git a/facefusion/process_manager.py b/facefusion/process_manager.py index a25b377c..17a580cc 100644 --- a/facefusion/process_manager.py +++ b/facefusion/process_manager.py @@ -51,11 +51,11 @@ def start() -> None: set_state('processing') -def stop_process() -> None: +def stop() -> None: set_state('stopping') -def end_process() -> None: +def end() -> None: set_state('pending') diff --git a/facefusion/workflows/modules/audio_to_image.py b/facefusion/workflows/modules/audio_to_image.py index df4ab48f..a5d1e33c 100644 --- a/facefusion/workflows/modules/audio_to_image.py +++ b/facefusion/workflows/modules/audio_to_image.py @@ -1,5 +1,6 @@ from functools import partial +from facefusion import process_manager from facefusion.types import ErrorCode from facefusion.workflows.as_frames import create_temp_frames from facefusion.workflows.core import clear, process_frames, setup @@ -21,10 +22,14 @@ def process(start_time : float) -> ErrorCode: clear ] + process_manager.start() + for task in tasks: error_code = task() #type:ignore[operator] if error_code > 0: + process_manager.end() return error_code + process_manager.end() return 0 diff --git a/facefusion/workflows/modules/audio_to_image_as_frames.py b/facefusion/workflows/modules/audio_to_image_as_frames.py index aa8295ae..9f14bf25 100644 --- a/facefusion/workflows/modules/audio_to_image_as_frames.py +++ b/facefusion/workflows/modules/audio_to_image_as_frames.py @@ -1,5 +1,6 @@ from functools import partial +from facefusion import process_manager from facefusion.types import ErrorCode from facefusion.workflows.as_frames import copy_temp_frames, create_temp_frames, finalize_frames from facefusion.workflows.core import clear, process_frames, setup @@ -19,10 +20,14 @@ def process(start_time : float) -> ErrorCode: clear ] + process_manager.start() + for task in tasks: error_code = task() #type:ignore[operator] if error_code > 0: + process_manager.end() return error_code + process_manager.end() return 0 diff --git a/facefusion/workflows/modules/image_to_image.py b/facefusion/workflows/modules/image_to_image.py index d84a5265..ed9f3654 100644 --- a/facefusion/workflows/modules/image_to_image.py +++ b/facefusion/workflows/modules/image_to_image.py @@ -1,5 +1,6 @@ from functools import partial +from facefusion import process_manager from facefusion.types import ErrorCode from facefusion.workflows.core import clear, setup from facefusion.workflows.to_image import analyse_image, finalize_image, prepare_image, process_image @@ -17,10 +18,14 @@ def process(start_time : float) -> ErrorCode: clear ] + process_manager.start() + for task in tasks: error_code = task() #type:ignore[operator] if error_code > 0: + process_manager.end() return error_code + process_manager.end() return 0 diff --git a/facefusion/workflows/modules/image_to_video.py b/facefusion/workflows/modules/image_to_video.py index 1410d723..011f8bdc 100644 --- a/facefusion/workflows/modules/image_to_video.py +++ b/facefusion/workflows/modules/image_to_video.py @@ -1,6 +1,6 @@ from functools import partial -from facefusion import state_manager +from facefusion import process_manager, state_manager from facefusion.types import ErrorCode from facefusion.workflows.core import clear, process_frames, setup from facefusion.workflows.to_video import analyse_video, create_temp_frames, finalize_video, merge_frames, process_memory_frames, restore_audio @@ -32,10 +32,14 @@ def process(start_time : float) -> ErrorCode: clear ]) + process_manager.start() + for task in tasks: error_code = task() #type:ignore[operator] if error_code > 0: + process_manager.end() return error_code + process_manager.end() return 0 diff --git a/facefusion/workflows/modules/image_to_video_as_frames.py b/facefusion/workflows/modules/image_to_video_as_frames.py index e11aa850..70729d7d 100644 --- a/facefusion/workflows/modules/image_to_video_as_frames.py +++ b/facefusion/workflows/modules/image_to_video_as_frames.py @@ -1,5 +1,6 @@ from functools import partial +from facefusion import process_manager from facefusion.types import ErrorCode from facefusion.workflows.as_frames import copy_temp_frames, finalize_frames from facefusion.workflows.core import clear, process_frames, setup @@ -19,10 +20,14 @@ def process(start_time : float) -> ErrorCode: clear ] + process_manager.start() + for task in tasks: error_code = task() #type:ignore[operator] if error_code > 0: + process_manager.end() return error_code + process_manager.end() return 0 diff --git a/facefusion/workflows/to_video.py b/facefusion/workflows/to_video.py index f7b87aa2..22395e5e 100644 --- a/facefusion/workflows/to_video.py +++ b/facefusion/workflows/to_video.py @@ -104,7 +104,7 @@ def process_memory_frames() -> ErrorCode: progress.update() if not video_manager.close_video_writer(video_writer): - process_manager.stop_process() + process_manager.stop() for processor_module in get_processors_modules(state_manager.get_item('processors')): processor_module.post_process() diff --git a/tests/test_core.py b/tests/test_core.py index b757110e..42bc6518 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -30,16 +30,11 @@ def test_process_step(mocker : MockerFixture, error_code : ErrorCode) -> None: conditional_process_mock = mocker.patch('facefusion.core.conditional_process', return_value = error_code) fork_session_mock = mocker.spy(session_manager, 'fork_session') - start_mock = mocker.spy(process_manager, 'start') - end_process_mock = mocker.spy(process_manager, 'end_process') assert core.process_step('job-id', 0, step_args) == error_code conditional_process_mock.assert_called_once_with() - assert start_mock.call_count == 1 - assert end_process_mock.call_count == 1 - assert session_manager.has_fork_session(local_id) is False fork_id = fork_session_mock.spy_return diff --git a/tests/test_ffmpeg.py b/tests/test_ffmpeg.py index f2c1c30e..6dd792a0 100644 --- a/tests/test_ffmpeg.py +++ b/tests/test_ffmpeg.py @@ -165,7 +165,7 @@ def test_await_process() -> None: assert ffmpeg_mock.call_count > 0 state_manager.clear_item('log_level') - process_manager.stop_process() + process_manager.stop() assert not await_process(ffmpeg.run_ffmpeg(commands)).wait() == 0 diff --git a/tests/test_process_manager.py b/tests/test_process_manager.py index 57c08e00..9d336d96 100644 --- a/tests/test_process_manager.py +++ b/tests/test_process_manager.py @@ -3,7 +3,7 @@ from typing import Iterator import pytest from facefusion import session_context, session_manager -from facefusion.process_manager import clear, end_process, get_state, init, is_pending, is_processing, is_stopping, set_state, start, stop_process +from facefusion.process_manager import clear, end, get_state, init, is_pending, is_processing, is_stopping, set_state, start, stop @pytest.fixture(scope = 'function', autouse = True) @@ -83,14 +83,14 @@ def test_start() -> None: def test_stop_process() -> None: set_state('processing') - stop_process() + stop() assert is_stopping() def test_end_process() -> None: set_state('processing') - end_process() + end() assert is_pending()