Skip to content

Commit

Permalink
passes mt context to ProcessPoolExecutor, fixes caching in test_commo…
Browse files Browse the repository at this point in the history
…n workflow
  • Loading branch information
rudolfix committed Oct 30, 2023
1 parent b6fb333 commit a648e07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
# path: ${{ steps.pip-cache.outputs.dir }}
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
key: venv-${{ matrix.os }}-${{ matrix.python-versions }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies + sentry
run: poetry install --no-interaction -E parquet -E pydantic && pip install sentry-sdk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_dbt_cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
with:
# path: ${{ steps.pip-cache.outputs.dir }}
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-dbt-cloud
key: venv-${{ matrix.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-dbt-cloud

- name: Install dependencies
# install dlt with postgres support
Expand Down
20 changes: 16 additions & 4 deletions dlt/common/runners/pool_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import multiprocessing
from typing import Callable, Union, cast, Any, TypeVar
from multiprocessing.pool import ThreadPool, Pool
from typing import Callable, Union, cast, TypeVar
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor, Future
from typing_extensions import ParamSpec

Expand All @@ -16,6 +15,11 @@
T = TypeVar("T")
P = ParamSpec("P")

# if TYPE_CHECKING:
# TItemFuture = Future[Union[TDataItems, DataItemWithMeta]]
# else:
# TItemFuture = Future


class NullExecutor(Executor):
"""Dummy executor that runs jobs single-threaded.
Expand All @@ -39,9 +43,17 @@ def create_pool(config: PoolRunnerConfiguration) -> Executor:
if config.pool_type == "process":
# if not fork method, provide initializer for logs and configuration
if multiprocessing.get_start_method() != "fork" and init._INITIALIZED:
return ProcessPoolExecutor(max_workers=config.workers, initializer=init.initialize_runtime, initargs=(init._RUN_CONFIGURATION,))
return ProcessPoolExecutor(
max_workers=config.workers,
initializer=init.initialize_runtime,
initargs=(init._RUN_CONFIGURATION,),
mp_context=multiprocessing.get_context()
)
else:
return ProcessPoolExecutor(max_workers=config.workers)
return ProcessPoolExecutor(
max_workers=config.workers,
mp_context=multiprocessing.get_context()
)
elif config.pool_type == "thread":
return ThreadPoolExecutor(max_workers=config.workers)
# no pool - single threaded
Expand Down

0 comments on commit a648e07

Please sign in to comment.