File: test_process_pool_executor.py

package info (click to toggle)
rasterio 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,732 kB
  • sloc: python: 23,119; sh: 947; makefile: 275; xml: 29
file content (25 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Tests for correct behavior of Rasterio's GDALEnv in concurrent programs"""

from concurrent.futures import ProcessPoolExecutor

import rasterio


def get_data(path):
    """Return all raster bands as an ndarray"""
    with rasterio.open(path, sharing=False) as src:
        return src.read()


def test_mp_main_env():
    """Get raster data using ProcessPoolExecutor with main thread Env"""
    with rasterio.Env(), ProcessPoolExecutor() as pool:
        for res in pool.map(get_data, ['tests/data/RGB.byte.tif'] * 10):
            assert res.any()


def test_mp_no_main_env():
    """Get raster data using ProcessPoolExecutor with main thread Env"""
    with ProcessPoolExecutor() as pool:
        for res in pool.map(get_data, ['tests/data/RGB.byte.tif'] * 10):
            assert res.any()