py_reactor_context (erlang_python v3.0.0)
View SourceReactor context process with FD ownership.
This module extends py_context with FD ownership and {select, ...} handling for the Erlang-as-Reactor architecture.
Each py_reactor_context process: - Owns a Python context (subinterpreter or worker) - Handles FD handoffs from py_reactor_acceptor - Receives {select, FdRes, Ref, ready_input/ready_output} messages from BEAM - Calls Python protocol handlers via reactor NIFs
Connection Lifecycle
1. Acceptor sends {fd_handoff, Fd, ClientInfo} to this process 2. Process registers FD via py_nif:reactor_register_fd/3 3. Process calls py_nif:reactor_init_connection/3 to create Python protocol 4. BEAM sends {select, FdRes, Ref, ready_input} when data is available 5. Process calls py_nif:reactor_on_read_ready/2 to process data 6. Python returns action (continue, write_pending, close) 7. Process acts on action (reselect read, select write, close)
Summary
Functions
Hand off a file descriptor to this reactor context.
Hand off a file descriptor to a specific reactor context.
Start a new py_reactor_context process.
Start a new py_reactor_context process with options.
Get context statistics.
Stop a py_reactor_context process.
Functions
Hand off a file descriptor to this reactor context.
The context takes ownership of the FD and will handle I/O events. This is the main entry point for handing off accepted connections.
Hand off a file descriptor to a specific reactor context.
-spec start_link(pos_integer(), atom()) -> {ok, pid()} | {error, term()}.
Start a new py_reactor_context process.
-spec start_link(pos_integer(), atom(), map()) -> {ok, pid()} | {error, term()}.
Start a new py_reactor_context process with options.
Options: - max_connections: Maximum connections per context (default: 100) - app_module: Python module containing ASGI/WSGI app - app_callable: Python callable name (e.g., "app", "application") - setup_code: Binary Python code to execute after context creation (useful for setting up protocol factory)
Get context statistics.
-spec stop(pid()) -> ok.
Stop a py_reactor_context process.