Skip to content

Commit

Permalink
Don't merge: choose Function Executor port randomly
Browse files Browse the repository at this point in the history
This is a hack to allow running multiple Executors on the same machine.
  • Loading branch information
eabatalov committed Jan 7, 2025
1 parent 68da27b commit a005315
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import signal
from typing import Any, Optional
import random

from .function_executor_server_factory import (
FunctionExecutorServerConfiguration,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a005315

Please sign in to comment.