Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ dependencies:
- python-dotenv==1.1.1
- shapely==2.1.2
- contextily==1.6.2
- stac_geoparquet==0.7.0
20 changes: 18 additions & 2 deletions stormhub/met/storm_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import logging
import multiprocessing
import os
import traceback
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
Expand Down Expand Up @@ -841,8 +842,12 @@ def multi_processor(
"""
if use_threads:
executor_class = ThreadPoolExecutor
mp_context = None
else:
# Use 'spawn' to avoid fork+asyncio deadlock: s3fs/fsspec runs a background
# asyncio thread whose locks are inherited locked by forked child processes.
executor_class = ProcessPoolExecutor
mp_context = multiprocessing.get_context("spawn")

if not os.path.exists(output_csv):
with open(output_csv, "w", encoding="utf-8") as f:
Expand All @@ -855,7 +860,11 @@ def multi_processor(
batch_size = max(min(num_workers // 3, 10), 2) if use_threads else num_workers
logging.info("Processing in batches of %d", batch_size)

with executor_class(max_workers=num_workers) as executor:
executor_kwargs = {"max_workers": num_workers}
if mp_context is not None:
executor_kwargs["mp_context"] = mp_context

with executor_class(**executor_kwargs) as executor:
for i in range(0, len(event_dates), batch_size):
batch = event_dates[i : i + batch_size]
futures = [executor.submit(func, catalog, date, storm_duration) for date in batch]
Expand Down Expand Up @@ -988,10 +997,13 @@ def create_items(

if use_threads:
executor_class = ThreadPoolExecutor
mp_context = None
# Force a non‑interactive backend (Agg) when threading.
matplotlib.use("Agg")
else:
# Use 'spawn' to avoid fork+asyncio deadlock from s3fs background threads.
executor_class = ProcessPoolExecutor
mp_context = multiprocessing.get_context("spawn")

storm_data = [(e["storm_date"], e["por_rank"]) for e in event_dates]
existing_item_ids = set()
Expand All @@ -1013,7 +1025,11 @@ def create_items(

count = len(storm_data)

with executor_class(max_workers=num_workers) as executor:
executor_kwargs = {"max_workers": num_workers}
if mp_context is not None:
executor_kwargs["mp_context"] = mp_context

with executor_class(**executor_kwargs) as executor:
futures = [
executor.submit(
storm_search,
Expand Down
Loading