Skip to content

Add async_pending action and reactor NIF support#14

Merged
benoitc merged 5 commits intomainfrom
feature/async-pending-support
Mar 8, 2026
Merged

Add async_pending action and reactor NIF support#14
benoitc merged 5 commits intomainfrom
feature/async-pending-support

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Mar 8, 2026

Summary

  • Add handoff/2,3 API for FD handoff to reactor contexts
  • Add setup_code option for protocol factory initialization
  • Add async_pending action for non-blocking ASGI task submission
  • Register reactor NIFs and fix erlang.reactor import path

benoitc added 5 commits March 8, 2026 01:47
- Add handoff/2,3 API functions for FD handoff
- Add setup_code option to run Python code in context
- Add async_pending action handling for task-based ASGI
- Add {write_ready, Fd} message handling for async completion
- Register reactor NIFs in nif_funcs table
- Fix erlang.reactor module import path in NIFs
- Add async_pending_test to py_reactor_SUITE
The reactor NIFs were using gil_acquire() which doesn't switch to the
context's subinterpreter state, causing segfaults when running Python
code in the wrong interpreter.

Changed nif_reactor_on_read_ready, nif_reactor_on_write_ready, and
nif_reactor_init_connection to use py_context_acquire/py_context_release
which properly handles thread state switching for subinterpreters.
Provides a clean API for protocols to signal async completion instead
of manually sending to the reactor PID. The reactor PID is stored per-fd
in init_connection and cleaned up in close_connection.
Added context parameter to reactor_close_fd NIF so it can properly
switch to the subinterpreter's thread state before calling Python.
@benoitc benoitc merged commit c79724e into main Mar 8, 2026
11 checks passed
@benoitc benoitc deleted the feature/async-pending-support branch March 8, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant