From a005315f1fd4d52be1dd02ae7eb540a6ddd45463 Mon Sep 17 00:00:00 2001 From: Eugene Batalov Date: Tue, 7 Jan 2025 14:00:26 +0000 Subject: [PATCH] Don't merge: choose Function Executor port randomly This is a hack to allow running multiple Executors on the same machine. --- .../server/subprocess_function_executor_server_factory.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-sdk/indexify/executor/function_executor/server/subprocess_function_executor_server_factory.py b/python-sdk/indexify/executor/function_executor/server/subprocess_function_executor_server_factory.py index ccc0750c1..701db5649 100644 --- a/python-sdk/indexify/executor/function_executor/server/subprocess_function_executor_server_factory.py +++ b/python-sdk/indexify/executor/function_executor/server/subprocess_function_executor_server_factory.py @@ -2,6 +2,7 @@ import os import signal from typing import Any, Optional +import random from .function_executor_server_factory import ( FunctionExecutorServerConfiguration, @@ -98,7 +99,9 @@ async def destroy( def _allocate_port(self) -> int: # No asyncio.Lock is required here because this operation never awaits # and it is always called from the same thread where the event loop is running. - return self._free_ports.pop() + port = random.choice(tuple(self._free_ports)) + self._free_ports.remove(port) + return port def _release_port(self, port: int) -> None: # No asyncio.Lock is required here because this operation never awaits