diff --git a/core/functionality.py b/core/functionality.py index 1e2d128..0a221fb 100644 --- a/core/functionality.py +++ b/core/functionality.py @@ -9,7 +9,10 @@ import yaml from datetime import datetime from typing import List -from multiprocessing.connection import Connection, PipeConnection, wait as multi_wait +from multiprocessing.connection import Connection, wait as multi_wait +# Need to import additional Connection type for Windows machines +if os.name == 'nt': + from multiprocessing.connection import PipeConnection from multiprocessing.queues import Queue from papermill.translators import papermill_translators from typing import Any, Dict @@ -49,6 +52,11 @@ def generate_id(prefix:str="", length:int=16, existing_ids:List[str]=[], f"using values '{charset}' and length of '{length}'.") def wait(inputs:List[VALID_CHANNELS])->List[VALID_CHANNELS]: + if os.name == 'nt': + return wait_windows(inputs) + return wait_linux(inputs) + +def wait_windows(inputs:List[VALID_CHANNELS])->List[VALID_CHANNELS]: all_connections = [i for i in inputs if type(i) is Connection] \ + [i for i in inputs if type(i) is PipeConnection] \ + [i._reader for i in inputs if type(i) is Queue] @@ -59,6 +67,15 @@ def wait(inputs:List[VALID_CHANNELS])->List[VALID_CHANNELS]: or (type(i) is Queue and i._reader in ready)] return ready_inputs +def wait_linux(inputs:List[VALID_CHANNELS])->List[VALID_CHANNELS]: + all_connections = [i for i in inputs if type(i) is Connection] \ + + [i._reader for i in inputs if type(i) is Queue] + ready = multi_wait(all_connections) + ready_inputs = [i for i in inputs if \ + (type(i) is Connection and i in ready) \ + or (type(i) is Queue and i._reader in ready)] + return ready_inputs + def _get_file_sha256(file_path): sha256_hash = hashlib.sha256()