From 2f84b2eb1fecab4c381ad2dfd31277717cc9df2d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 2 Jun 2022 12:57:18 +0300 Subject: Enable user abortion of file parsing Enable the user to abort the background parsing of the file. --- quality_control/parsing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'quality_control') diff --git a/quality_control/parsing.py b/quality_control/parsing.py index 5b1809b..9f8e8ee 100644 --- a/quality_control/parsing.py +++ b/quality_control/parsing.py @@ -4,7 +4,7 @@ import os import collections from enum import Enum from functools import partial -from typing import Union, Iterable, Generator, Callable +from typing import Iterable, Generator, Callable, Optional import quality_control.average as avg import quality_control.standard_error as se @@ -65,7 +65,8 @@ def se_errors(line_number, fields): def collect_errors( filepath: str, filetype: FileType, strains: list, - update_progress: Union[Callable, None] = None) -> Generator: + update_progress: Optional[Callable] = None, + user_aborted: Optional[Callable] = lambda: False) -> Generator: """Run checks against file and collect all the errors""" errors = tuple() def __process_errors__(line_number, line, error_checker_fn, errors = tuple()): @@ -80,6 +81,9 @@ def collect_errors( with open(filepath, encoding="utf-8") as input_file: for line_number, line in enumerate(input_file, start=1): + if user_aborted(): + break + if line_number == 1: for error in __process_errors__( line_number, line, partial(header_errors, strains=strains), -- cgit v1.2.3