diff --git a/cars/applications/grid_generation/epipolar_grid_generation.py b/cars/applications/grid_generation/epipolar_grid_generation.py index 38f13c39..5ef5f4ba 100644 --- a/cars/applications/grid_generation/epipolar_grid_generation.py +++ b/cars/applications/grid_generation/epipolar_grid_generation.py @@ -176,19 +176,20 @@ def run( ) logging.info( - "Left satellite acquisition angles: Azimuth angle: {:.1f}°, " - "Elevation angle: {:.1f}°".format(left_az, left_elev_angle) + "Left satellite acquisition angles: " + "Azimuth angle: {:.1f} degrees, " + "Elevation angle: {:.1f} degrees".format(left_az, left_elev_angle) ) logging.info( - "Right satellite acquisition angles: Azimuth angle: {:.1f}°, " - "Elevation angle: {:.1f}°".format(right_az, right_elev_angle) + "Right satellite acquisition angles: " + "Azimuth angle: {:.1f} degrees, " + "Elevation angle: {:.1f} degrees".format(right_az, right_elev_angle) ) logging.info( - "Stereo satellite convergence angle from ground: {:.1f}°".format( - convergence_angle - ) + "Stereo satellite convergence angle from ground: " + "{:.1f} degrees".format(convergence_angle) ) # Generate rectification grids diff --git a/cars/core/cars_logging.py b/cars/core/cars_logging.py index 4a365b83..6f652225 100644 --- a/cars/core/cars_logging.py +++ b/cars/core/cars_logging.py @@ -25,15 +25,41 @@ and workers """ -import fcntl import logging import logging.config import os +import platform # Standard imports from datetime import datetime from functools import wraps +SYS_PLATFORM = platform.system().lower() +IS_WIN = "windows" == SYS_PLATFORM + +if IS_WIN: + import msvcrt # pylint: disable=E0401 + + def lock(file): + """Lock file for safe writing (Windows version)""" + msvcrt.locking(file.fileno(), msvcrt.LK_LOCK, 0) + + def unlock(file): + """Unlock file for safe writing (Windows version)""" + msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 0) + +else: + import fcntl + + def lock(file): + """Lock file for safe writing (Unix version)""" + fcntl.flock(file, fcntl.LOCK_EX) + + def unlock(file): + """Unlock file for safe writing (Unix version)""" + fcntl.flock(file, fcntl.LOCK_UN) + + PROGRESS = 21 logging.addLevelName(PROGRESS, "PROGRESS") PROFILING_LOG = 15 @@ -90,9 +116,9 @@ def write_log(self, msg) -> None: Write log """ with open(self.log_file, "a", encoding="utf-8") as file: - fcntl.flock(file, fcntl.LOCK_EX) + lock(file) file.write(msg) - fcntl.flock(file, fcntl.LOCK_UN) + unlock(file) def setup_logging( diff --git a/cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py b/cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py index 67cde9c7..82397d30 100644 --- a/cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py +++ b/cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py @@ -31,6 +31,7 @@ # Standard imports import multiprocessing as mp import os +import platform import shutil import signal import threading @@ -58,6 +59,9 @@ ) from cars.orchestrator.cluster.mp_cluster.mp_tools import replace_data +SYS_PLATFORM = platform.system().lower() +IS_WIN = "windows" == SYS_PLATFORM + RUN = 0 TERMINATE = 1 @@ -106,14 +110,17 @@ def __init__(self, conf_cluster, out_dir, launch_worker=True): self.factorize_tasks = self.checked_conf_cluster["factorize_tasks"] # Set multiprocessing mode # forkserver is used, to allow OMP to be used in numba - mp_mode = "forkserver" + mp_mode = "spawn" if IS_WIN else "forkserver" self.launch_worker = launch_worker self.tmp_dir = None # affinity issues caused by numpy - os.system("taskset -p 0xffffffff %d > /dev/null 2>&1" % os.getpid()) + if IS_WIN is False: + os.system( + "taskset -p 0xffffffff %d > /dev/null 2>&1" % os.getpid() + ) if self.launch_worker: # Create wrapper object diff --git a/cars/orchestrator/orchestrator.py b/cars/orchestrator/orchestrator.py index 0d0436f0..6bb42945 100644 --- a/cars/orchestrator/orchestrator.py +++ b/cars/orchestrator/orchestrator.py @@ -22,10 +22,13 @@ this module contains the orchestrator class """ -# Standard imports import collections import logging + +# Standard imports +import multiprocessing import os +import platform import shutil import sys @@ -51,6 +54,9 @@ from cars.orchestrator.registry import replacer_registry, saver_registry from cars.orchestrator.tiles_profiler import TileProfiler +SYS_PLATFORM = platform.system().lower() +IS_WIN = "windows" == SYS_PLATFORM + class Orchestrator: """ @@ -105,7 +111,11 @@ def __init__( "Auto mode is used for orchestator: " "parameters set by user are ignored" ) - available_cpu = len(os.sched_getaffinity(0)) + available_cpu = ( + multiprocessing.cpu_count() + if IS_WIN + else len(os.sched_getaffinity(0)) + ) if available_cpu == 1: logging.warning("Only one CPU detected.") nb_workers = max(1, available_cpu - 1) diff --git a/setup.cfg b/setup.cfg index 13e62341..1a0bd352 100644 --- a/setup.cfg +++ b/setup.cfg @@ -81,7 +81,7 @@ install_requires = cars-rasterize==0.2.* cars-resample==0.1.* vlsift==0.1.* - shareloc==0.2.1 + shareloc==0.2.2 package_dir = . = cars