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
4 changes: 2 additions & 2 deletions pasha/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class PoolContext(MapContext):
"""

def __init__(self, num_workers=None):
from os import cpu_count

if num_workers is None:
if not num_workers:
from os import cpu_count
num_workers = min(cpu_count() // 2, 10)

super().__init__(num_workers=num_workers)
Expand Down
11 changes: 10 additions & 1 deletion pasha/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import numpy as np
import pasha as psh
from pasha.context import MapContext
from pasha.context import MapContext, ThreadContext
from pasha.functor import Functor


Expand Down Expand Up @@ -123,3 +123,12 @@ def test_set_default_context_string(ctx_str, expected_type):

psh.set_default_context(ctx_str)
assert isinstance(psh.get_default_context(), expected_type)


@pytest.mark.parametrize(
['num_workers', 'expected'], [(None, 1), (0, 1), (4, 4)])
def test_array(num_workers, expected):
"""Test ThreadContext validation."""

ctx = ThreadContext(num_workers=num_workers)
assert ctx.num_workers >= expected