Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing azure functions in InitRequest by default #1250

Merged
merged 12 commits into from
Jul 28, 2023
3 changes: 0 additions & 3 deletions azure_functions_worker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"""
UNIX_SHARED_MEMORY_DIRECTORIES = "FUNCTIONS_UNIX_SHARED_MEMORY_DIRECTORIES"

# Flag to enable loading functions at init request
PYTHON_LOAD_FUNCTIONS_INIT = "PYTHON_LOAD_FUNCTIONS_INIT"

# Setting Defaults
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT = 1
PYTHON_THREADPOOL_THREAD_COUNT_MIN = 1
Expand Down
13 changes: 3 additions & 10 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
PYTHON_ENABLE_DEBUG_LOGGING, SCRIPT_FILE_NAME,
PYTHON_LANGUAGE_RUNTIME, PYTHON_LOAD_FUNCTIONS_INIT)
PYTHON_LANGUAGE_RUNTIME)
from .extension import ExtensionManager
from .logging import disable_console_logging, enable_console_logging
from .logging import enable_debug_logging_recommendation
Expand Down Expand Up @@ -288,10 +288,9 @@ async def _handle__worker_init_request(self, request):
if not DependencyManager.is_in_linux_consumption():
DependencyManager.prioritize_customer_dependencies()

if DependencyManager.is_in_linux_consumption() \
and is_envvar_true(PYTHON_LOAD_FUNCTIONS_INIT):
if DependencyManager.is_in_linux_consumption():
logger.info(
"PYTHON_LOAD_FUNCTIONS_INIT enabled. Importing azure functions")
"Importing azure functions in WorkerInitRequest")
import azure.functions # NoQA

# loading bindings registry and saving results to a static
Expand Down Expand Up @@ -539,12 +538,6 @@ async def _handle__function_environment_reload_request(self, request):
func_env_reload_request = \
request.function_environment_reload_request

if not is_envvar_true(PYTHON_LOAD_FUNCTIONS_INIT):
# Import before clearing path cache so that the default
# azure.functions modules is available in sys.modules for
# customer use
import azure.functions # NoQA

# Append function project root to module finding sys.path
if func_env_reload_request.function_app_directory:
sys.path.append(func_env_reload_request.function_app_directory)
Expand Down
2 changes: 0 additions & 2 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,6 @@ async def test_dispatcher_load_azfunc_in_init(self):
"""Test if the dispatcher's log can be flushed out during worker
initialization
"""
os.environ.update({"CONTAINER_NAME": 'test',
"PYTHON_LOAD_FUNCTIONS_INIT": "1"})
async with self._ctrl as host:
r = await host.init_worker('4.15.1')
self.assertEqual(
Expand Down