Skip to content

Commit

Permalink
Merge branch 'fix-windows' into 'master'
Browse files Browse the repository at this point in the history
Windows compatibility

Closes #854

See merge request 3d/cars-park/cars!732
  • Loading branch information
dyoussef committed Aug 22, 2024
2 parents 7d4d0f0 + 3178785 commit a209cf5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
15 changes: 8 additions & 7 deletions cars/applications/grid_generation/epipolar_grid_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions cars/core/cars_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# Standard imports
import multiprocessing as mp
import os
import platform
import shutil
import signal
import threading
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions cars/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
"""
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a209cf5

Please sign in to comment.