Skip to content

Commit c9edec2

Browse files
author
Victoria Hall
committed
Merge branch 'hallvictoria/config_file' of https://github.com/Azure/azure-functions-python-worker into hallvictoria/config_file
2 parents 193282c + 8834535 commit c9edec2

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .bindings.shared_memory_data_transfer import SharedMemoryManager
2525
from .constants import (
2626
APPLICATIONINSIGHTS_CONNECTION_STRING,
27+
HTTP_URI,
2728
METADATA_PROPERTIES_WORKER_INDEXED,
2829
PYTHON_AZURE_MONITOR_LOGGER_NAME,
2930
PYTHON_AZURE_MONITOR_LOGGER_NAME_DEFAULT,
@@ -38,8 +39,7 @@
3839
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
3940
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
4041
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
41-
REQUIRES_ROUTE_PARAMETERS,
42-
HTTP_URI
42+
REQUIRES_ROUTE_PARAMETERS
4343
)
4444
from .extension import ExtensionManager
4545
from .http_v2 import (
@@ -976,7 +976,7 @@ def tp_max_workers_validator(value: str) -> bool:
976976

977977
# Starting Python 3.9, worker won't be putting a limit on the
978978
# max_workers count in the created threadpool.
979-
default_value = None if sys.version_info.minor == 9 \
979+
default_value = None if sys.version_info.minor >= 9 \
980980
else f'{PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT}'
981981

982982
max_workers = config_manager.get_app_setting(

azure_functions_worker/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
VERSION = '4.31.0'
4+
VERSION = '4.32.0'

tests/unittests/test_dispatcher.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
from azure_functions_worker import protos
1616
from azure_functions_worker.constants import (
17+
HTTP_URI,
1718
METADATA_PROPERTIES_WORKER_INDEXED,
1819
PYTHON_ENABLE_DEBUG_LOGGING,
1920
PYTHON_ENABLE_INIT_INDEXING,
2021
PYTHON_THREADPOOL_THREAD_COUNT,
2122
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
2223
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
23-
PYTHON_THREADPOOL_THREAD_COUNT_MIN, HTTP_URI, REQUIRES_ROUTE_PARAMETERS,
24+
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
25+
REQUIRES_ROUTE_PARAMETERS
2426
)
2527
from azure_functions_worker.dispatcher import Dispatcher, ContextEnabledTask
2628
from azure_functions_worker.utils.config_manager import config_manager
@@ -552,15 +554,15 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
552554
"as the default passed is None, the cpu_count determines the "
553555
"number of max_workers and we cannot mock the os.cpu_count() "
554556
"in the concurrent.futures.ThreadPoolExecutor")
555-
class TestThreadPoolSettingsPython39(TestThreadPoolSettingsPython38):
557+
class TestThreadPoolSettingsPython39(TestThreadPoolSettingsPython37):
556558
def setUp(self, version=SysVersionInfo(3, 9, 0, 'final', 0)):
557559
super(TestThreadPoolSettingsPython39, self).setUp(version)
558-
559560
self.mock_os_cpu = patch(
560561
'os.cpu_count', return_value=2)
561562
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
562563
self._default_workers: Optional[int] = 6
563564
self.mock_os_cpu.start()
565+
self._allowed_max_workers: int = self._over_max_workers
564566

565567
def tearDown(self):
566568
self.mock_os_cpu.stop()
@@ -572,11 +574,19 @@ def tearDown(self):
572574
"as the default passed is None, the cpu_count determines the "
573575
"number of max_workers and we cannot mock the os.cpu_count() "
574576
"in the concurrent.futures.ThreadPoolExecutor")
575-
class TestThreadPoolSettingsPython310(TestThreadPoolSettingsPython39):
577+
class TestThreadPoolSettingsPython310(TestThreadPoolSettingsPython37):
576578
def setUp(self, version=SysVersionInfo(3, 10, 0, 'final', 0)):
577579
super(TestThreadPoolSettingsPython310, self).setUp(version)
580+
self._allowed_max_workers: int = self._over_max_workers
581+
self.mock_os_cpu = patch(
582+
'os.cpu_count', return_value=2)
583+
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
584+
self._default_workers: Optional[int] = 6
585+
self.mock_os_cpu.start()
586+
self._allowed_max_workers: int = self._over_max_workers
578587

579588
def tearDown(self):
589+
self.mock_os_cpu.stop()
580590
super(TestThreadPoolSettingsPython310, self).tearDown()
581591

582592

@@ -585,12 +595,41 @@ def tearDown(self):
585595
"as the default passed is None, the cpu_count determines the "
586596
"number of max_workers and we cannot mock the os.cpu_count() "
587597
"in the concurrent.futures.ThreadPoolExecutor")
588-
class TestThreadPoolSettingsPython311(TestThreadPoolSettingsPython310):
598+
class TestThreadPoolSettingsPython311(TestThreadPoolSettingsPython37):
589599
def setUp(self, version=SysVersionInfo(3, 11, 0, 'final', 0)):
590600
super(TestThreadPoolSettingsPython311, self).setUp(version)
601+
self._allowed_max_workers: int = self._over_max_workers
602+
self.mock_os_cpu = patch(
603+
'os.cpu_count', return_value=2)
604+
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
605+
self._default_workers: Optional[int] = 6
606+
self.mock_os_cpu.start()
607+
self._allowed_max_workers: int = self._over_max_workers
591608

592609
def tearDown(self):
593-
super(TestThreadPoolSettingsPython310, self).tearDown()
610+
self.mock_os_cpu.stop()
611+
super(TestThreadPoolSettingsPython311, self).tearDown()
612+
613+
614+
@unittest.skipIf(sys.version_info.minor != 12,
615+
"Run the tests only for Python 3.12. In other platforms, "
616+
"as the default passed is None, the cpu_count determines the "
617+
"number of max_workers and we cannot mock the os.cpu_count() "
618+
"in the concurrent.futures.ThreadPoolExecutor")
619+
class TestThreadPoolSettingsPython312(TestThreadPoolSettingsPython37):
620+
def setUp(self, version=SysVersionInfo(3, 12, 0, 'final', 0)):
621+
super(TestThreadPoolSettingsPython312, self).setUp(version)
622+
self._allowed_max_workers: int = self._over_max_workers
623+
self.mock_os_cpu = patch(
624+
'os.cpu_count', return_value=2)
625+
# 6 - based on 2 cores - min(32, (os.cpu_count() or 1) + 4) - 2 + 4
626+
self._default_workers: Optional[int] = 6
627+
self.mock_os_cpu.start()
628+
self._allowed_max_workers: int = self._over_max_workers
629+
630+
def tearDown(self):
631+
self.mock_os_cpu.stop()
632+
super(TestThreadPoolSettingsPython312, self).tearDown()
594633

595634

596635
class TestDispatcherStein(testutils.AsyncTestCase):

0 commit comments

Comments
 (0)