Skip to content

Conversation

@gavin-aguiar
Copy link
Contributor

@gavin-aguiar gavin-aguiar commented Aug 18, 2025

Description

Refactored threadpool lifecycle management from proxy worker to runtime libraries (v1 & v2):

Proxy Worker Changes

  • Removed internal threadpool creation/management logic from dispatcher.py
  • Removed _sync_call_tp attribute and related methods (_create_sync_call_tp, _stop_sync_call_tp, _get_sync_tp_max_workers)
  • Added direct calls to runtime APIs: start_threadpool_executor() during init/reload
  • Removed passing threadpool via invocation properties

Runtime Library Additions

  • Added threadpool.py modules to both v1 and v2 runtimes
  • Implemented centralized threadpool management:
  • start_threadpool_executor() - creates/replaces executor with PYTHON_THREADPOOL_THREAD_COUNT validation
  • stop_threadpool_executor() - graceful shutdown
  • get_threadpool_executor() - thread-safe accessor
  • Updated handle_event.py in both runtimes to fetch executor internally
  • Added public API exports in runtime init.py files

Testing

  • Added comprehensive unit tests for threadpool functionality (v1 & v2)
  • Added dispatcher tests validating threadpool delegation behavior
  • Fixed flake8 style issues across modified files
  • Fixed v2 runtime flake8 test discovery (repo root resolution)

Pull Request Checklist

Host-Worker Contract

  • Does this PR impact the host-worker contract (e.g., gRPC messages, shared interfaces)?
    • If yes, have the changes been applied to:
      • azure_functions_worker (Python <= 3.12)
      • proxy_worker (Python >= 3.13)
    • If no, please explain why:

Worker Execution Logic

  • Does this PR affect worker execution logic (e.g., function invocation, bindings, lifecycle)?
    If yes, please answer the following:

Python Version Coverage

  • Does this change apply to both Python <=3.12 and 3.13+?
  • If yes, have the changes been made to:
    • azure_functions_worker (Python <= 3.12)
    • runtimes/v1 / runtimes/v2 (Python >= 3.13)
  • If no, please explain why:

Programming Model Compatibility (for Python 3.13+)

  • Does this change apply to both:
    • V1 programming model (runtimes/v1)?
    • V2 programming model (runtimes/v2)?
  • Explanation (if limited to one model):
@gavin-aguiar gavin-aguiar changed the title Moving threadpool configs to the library worker refactor: Moving threadpool configs to the library worker Aug 18, 2025
@gavin-aguiar gavin-aguiar marked this pull request as ready for review August 20, 2025 19:09
hallvictoria
hallvictoria previously approved these changes Aug 22, 2025
@gavin-aguiar gavin-aguiar merged commit 89defbe into dev Aug 26, 2025
39 checks passed
@gavin-aguiar gavin-aguiar deleted the gaaguiar/tptc_refactor branch August 26, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants