Skip to content

Commit ea39bc6

Browse files
committed
attempt to relax open limits before forking
1 parent 0ac2573 commit ea39bc6

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

topo_map_processor/tools/retile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from pmtiles_mosaic.tile_sources import create_source_from_paths, MissingTileError
2828

29+
from .utils import relax_open_file_limit
30+
2931
def run_external(cmd):
3032
print(f'running cmd - {cmd}')
3133
start = time.time()
@@ -445,6 +447,8 @@ def retile_main(args):
445447
if tile_extension == 'jpg':
446448
tile_extension = 'jpeg'
447449

450+
relax_open_file_limit()
451+
448452
os.environ['GDAL_CACHEMAX'] = '2048'
449453
os.environ['GDAL_MAX_DATASET_POOL_SIZE'] = '5000'
450454
os.environ['GDAL_DISABLE_READDIR_ON_OPEN'] = 'TRUE'

topo_map_processor/tools/tile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
from osgeo_utils.gdal2tiles import submain as gdal2tiles_main
1515

16+
from .utils import relax_open_file_limit
17+
1618
SUPPORTED_FORMATS = ['webp', 'jpeg', 'png']
1719

1820
def run_external(cmd):
@@ -95,6 +97,7 @@ def cli():
9597
else:
9698
attribution_text = args.attribution
9799

100+
relax_open_file_limit()
98101

99102
tiles_dir = Path(args.tiles_dir)
100103
tiles_dir.mkdir(parents=True, exist_ok=True)

topo_map_processor/tools/utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import resource
3+
4+
5+
def relax_open_file_limit():
6+
7+
# Get the current soft and hard limits for open files
8+
current_soft, current_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
9+
print(f"Current open file limits: Soft={current_soft}, Hard={current_hard}")
10+
11+
# Set new soft and hard limits for open files
12+
new_soft = resource.RLIM_INFINITY # Set to unlimited
13+
new_hard = resource.RLIM_INFINITY # Set to unlimited
14+
15+
try:
16+
resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, new_hard))
17+
print(f"New open file limits set: Soft={new_soft}, Hard={new_hard}")
18+
except Exception as e:
19+
print(f"Error setting resource limit to unlimited: {e}")
20+
print('Increasing soft limit to match the hard limit instead')
21+
new_soft = current_hard
22+
new_hard = current_hard
23+
try:
24+
resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, new_hard))
25+
print(f"New open file limits set: Soft={new_soft}, Hard={new_hard}")
26+
except Exception as e:
27+
print(f"Error setting soft resource limit to match hard limit: {e}")
28+
29+
# Verify the new limits
30+
updated_soft, updated_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
31+
print(f"Verified open file limits: Soft={updated_soft}, Hard={updated_hard}")

0 commit comments

Comments
 (0)