Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Support Windows job and cache primitives

Cinna Davis246df1c1c08b
diff --git a/.github/workflows/windows-smoke.yml b/.github/workflows/windows-smoke.yml
new file mode 100644
index 0000000..72aba4f
--- /dev/null
+++ b/.github/workflows/windows-smoke.yml
@@ -0,0 +1,16 @@
+name: Windows smoke
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+jobs:
+ windows:
+ runs-on: windows-2025
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
+ with:
+ python-version: '3.12'
+ - run: python -m pip install .
+ - run: dopplergeist --help
+ - run: python scripts/windows_smoke.py
diff --git a/pyproject.toml b/pyproject.toml
index 58702d1..d3eaa62 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,7 +24,7 @@ classifiers = [
license = "PolyForm-Noncommercial-1.0.0"
license-files = ["LICENSE", "licenses/MIT-legacy.txt", "src/dopplergeist/web/leaflet-license.txt"]
requires-python = ">=3.11"
-dependencies = ["numpy", "scipy", "numba>=0.62.1,<0.63; sys_platform == 'darwin' and platform_machine == 'x86_64'", "numba>=0.68.1; sys_platform != 'darwin' or platform_machine != 'x86_64'", "pandas", "soundfile", "pyproj>=3.7.2", "rasterio", "matplotlib", "requests", "pyarrow", "shapely>=2.0"]
+dependencies = ["numpy", "scipy", "numba>=0.62.1,<0.63; sys_platform == 'darwin' and platform_machine == 'x86_64'", "numba>=0.68.1; sys_platform != 'darwin' or platform_machine != 'x86_64'", "pandas", "soundfile", "pyproj>=3.7.2", "rasterio", "matplotlib", "requests", "pyarrow", "shapely>=2.0", "portalocker>=2.8"]
[project.urls]
Homepage = "https://github.com/1337isnot1337/DOPPLERGEIST"
@@ -52,4 +52,4 @@ testpaths = ["tests"]
[tool.cibuildwheel]
build = "cp311-* cp312-* cp313-* cp314-*"
skip = "*-musllinux_* cp314-macosx_x86_64"
-test-command = "dopplergeist --help && python -c \"import sys, dopplergeist.advanced_discovery; from importlib.resources import files; assert files('dopplergeist.web').joinpath('index.html').is_file(); sys.platform == 'win32' or __import__('dopplergeist.jobs'); sys.platform == 'win32' or __import__('dopplergeist.tiled_search')\""
+test-command = "dopplergeist --help && python -c \"import sys, dopplergeist.advanced_discovery; from importlib.resources import files; assert files('dopplergeist.web').joinpath('index.html').is_file(); __import__('dopplergeist.jobs'); __import__('dopplergeist.tiled_search')\""
diff --git a/scripts/windows_smoke.py b/scripts/windows_smoke.py
new file mode 100644
index 0000000..e4b129f
--- /dev/null
+++ b/scripts/windows_smoke.py
@@ -0,0 +1,35 @@
+"""Exercise platform services without starting an analysis or generating audio."""
+import os
+import subprocess
+import sys
+import tempfile
+from pathlib import Path
+
+from dopplergeist.data_access import cache_lock
+from dopplergeist.jobs import JobManager
+from dopplergeist.resource_usage import process_peak_rss_kib
+import dopplergeist.tiled_search # noqa: F401
+
+with tempfile.TemporaryDirectory() as root:
+ root = Path(root)
+ with cache_lock(root / 'cache.lock'):
+ pass
+ manager = JobManager(root / 'jobs')
+ try:
+ try:
+ JobManager(root / 'jobs')
+ except ValueError:
+ pass
+ else:
+ raise AssertionError('second job manager acquired the same lock')
+ process = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(60)'],
+ start_new_session=(os.name != 'nt'),
+ creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == 'nt' else 0)
+ JobManager._stop(process)
+ assert process.poll() is not None
+ finally:
+ manager.close()
+ manager = JobManager(root / 'jobs')
+ manager.close()
+ assert process_peak_rss_kib() > 0
+print('Platform smoke checks passed')
diff --git a/src/dopplergeist/data_access.py b/src/dopplergeist/data_access.py
index a966ffd..7e86924 100644
--- a/src/dopplergeist/data_access.py
+++ b/src/dopplergeist/data_access.py
@@ -271,11 +271,11 @@ def write_json(path, value, *, compact=False):
@contextmanager
def cache_lock(path):
- import fcntl
+ import portalocker
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("a") as lock:
- fcntl.flock(lock, fcntl.LOCK_EX)
+ portalocker.lock(lock, portalocker.LOCK_EX)
yield
diff --git a/src/dopplergeist/jobs.py b/src/dopplergeist/jobs.py
index 89ec199..46992af 100644
--- a/src/dopplergeist/jobs.py
+++ b/src/dopplergeist/jobs.py
@@ -1,7 +1,7 @@
"""Persistent local jobs; each analysis has its own cancellable process group."""
import argparse
from contextlib import contextmanager
-import fcntl
+import portalocker
import hashlib
import json
import math
@@ -71,11 +71,11 @@ def _evidence(value):
def _control_lock(directory):
"""Serialize a local cancel request with the manager's final result."""
with (directory / ".control.lock").open("a") as lockfile:
- fcntl.flock(lockfile, fcntl.LOCK_EX)
+ portalocker.lock(lockfile, portalocker.LOCK_EX)
try:
yield
finally:
- fcntl.flock(lockfile, fcntl.LOCK_UN)
+ portalocker.unlock(lockfile)
def request_local_cancel(root, job_id):
@@ -96,13 +96,13 @@ def request_local_cancel(root, job_id):
return current
lock_path = root / ".manager.lock"
try:
- with lock_path.open("rb") as lockfile:
+ with lock_path.open("a+") as lockfile:
try:
- fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
- except BlockingIOError:
+ portalocker.lock(lockfile, portalocker.LOCK_EX | portalocker.LOCK_NB)
+ except portalocker.exceptions.LockException:
manager_active = True
else:
- fcntl.flock(lockfile.fileno(), fcntl.LOCK_UN)
+ portalocker.unlock(lockfile)
manager_active = False
except FileNotFoundError:
manager_active = False
@@ -128,8 +128,8 @@ class JobManager:
raise ValueError("Job limits must be positive")
self._lockfile = (self.root / ".manager.lock").open("a")
try:
- fcntl.flock(self._lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except BlockingIOError:
+ portalocker.lock(self._lockfile, portalocker.LOCK_EX | portalocker.LOCK_NB)
+ except portalocker.exceptions.LockException:
self._lockfile.close()
raise ValueError("Another job manager is using this directory") from None
self._mutex = threading.RLock()
@@ -230,7 +230,9 @@ class JobManager:
if resume:
command.append("--resume")
process = subprocess.Popen(command,
- stdout=log, stderr=subprocess.STDOUT, env=env, start_new_session=True)
+ stdout=log, stderr=subprocess.STDOUT, env=env,
+ start_new_session=(os.name != "nt"),
+ creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0)
self._processes[directory.name] = process
deadline = time.monotonic() + self.max_runtime_s
while True:
@@ -278,6 +280,13 @@ class JobManager:
@staticmethod
def _stop(process):
if process.poll() is None:
+ if os.name == "nt":
+ subprocess.run(["taskkill", "/PID", str(process.pid), "/T", "/F"],
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False)
+ if process.poll() is None:
+ process.kill()
+ process.wait()
+ return
os.killpg(process.pid, signal.SIGTERM)
try:
process.wait(timeout=3)
diff --git a/src/dopplergeist/resource_usage.py b/src/dopplergeist/resource_usage.py
index 043989e..35ce4d7 100644
--- a/src/dopplergeist/resource_usage.py
+++ b/src/dopplergeist/resource_usage.py
@@ -1,5 +1,4 @@
"""Process-local resource measurements."""
-import resource
import sys
@@ -19,5 +18,26 @@ def process_peak_rss_kib():
return int(fields[1])
except (OSError, ValueError):
pass
+ if sys.platform == "win32":
+ import ctypes
+ from ctypes import wintypes
+
+ class Counters(ctypes.Structure):
+ _fields_ = [("cb", wintypes.DWORD), ("PageFaultCount", wintypes.DWORD)] + [
+ (name, ctypes.c_size_t) for name in (
+ "PeakWorkingSetSize", "WorkingSetSize", "QuotaPeakPagedPoolUsage",
+ "QuotaPagedPoolUsage", "QuotaPeakNonPagedPoolUsage", "QuotaNonPagedPoolUsage",
+ "PagefileUsage", "PeakPagefileUsage")]
+
+ counters = Counters()
+ counters.cb = ctypes.sizeof(counters)
+ kernel = ctypes.WinDLL("kernel32", use_last_error=True)
+ psapi = ctypes.WinDLL("psapi", use_last_error=True)
+ kernel.GetCurrentProcess.restype = wintypes.HANDLE
+ psapi.GetProcessMemoryInfo.argtypes = [wintypes.HANDLE, ctypes.POINTER(Counters), wintypes.DWORD]
+ if not psapi.GetProcessMemoryInfo(kernel.GetCurrentProcess(), ctypes.byref(counters), counters.cb):
+ raise ctypes.WinError(ctypes.get_last_error())
+ return counters.PeakWorkingSetSize / 1024
+ import resource
peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
return peak / 1024 if sys.platform == 'darwin' else peak
diff --git a/src/dopplergeist/terrain.py b/src/dopplergeist/terrain.py
index 3070778..a8cff9f 100644
--- a/src/dopplergeist/terrain.py
+++ b/src/dopplergeist/terrain.py
@@ -191,9 +191,9 @@ class CopernicusTerrain:
continue
path=self.cache/(tag+".tif")
if not path.exists():
- import fcntl
+ import portalocker
with path.with_suffix(".lock").open("a") as lock:
- fcntl.flock(lock,fcntl.LOCK_EX)
+ portalocker.lock(lock, portalocker.LOCK_EX)
if not path.exists():
url=f"https://copernicus-dem-90m.s3.amazonaws.com/{tag}/{tag}.tif"
r=self.session.get(url,timeout=120);r.raise_for_status()