Skip to content

Commit a46b940

Browse files
authored
Merge pull request #18 from benoitc/feature/channel-api
Add asyncio-compatible Channel API
2 parents a494b14 + 96dd12b commit a46b940

File tree

13 files changed

+2767
-7
lines changed

13 files changed

+2767
-7
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
## Unreleased
44

5-
<<<<<<< HEAD
65
### Added
76

7+
- **Channel API** - Bidirectional message passing between Erlang and Python
8+
- `py_channel:new/0,1` - Create channels with optional backpressure (`max_size`)
9+
- `py_channel:send/2` - Send Erlang terms to Python (returns `busy` on backpressure)
10+
- `py_channel:close/1` - Close channel, signals `StopIteration` to Python
11+
- Python `Channel` class with sync and async interfaces:
12+
- `channel.receive()` - Blocking receive (suspends Python, yields to Erlang)
13+
- `channel.try_receive()` - Non-blocking receive
14+
- `await channel.async_receive()` - Asyncio-compatible receive
15+
- `for msg in channel:` - Sync iteration
16+
- `async for msg in channel:` - Async iteration
17+
- `erlang.channel.reply(pid, term)` - Send messages to Erlang processes
18+
- Zero-copy IOQueue buffering via `enif_ioq`
19+
- 8x faster than Reactor for small messages, 2x faster for 16KB messages
20+
821
- **OWN_GIL Subinterpreter Thread Pool** - True parallelism with Python 3.12+ subinterpreters
922
- Each subinterpreter runs in its own thread with its own GIL (`Py_GIL_OWN`)
1023
- Thread pool manages N subinterpreters for parallel Python execution

c_src/py_callback.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,9 +2400,15 @@ static int create_erlang_module(void) {
24002400
" erlang.ExecutionMode = _erlang_impl.ExecutionMode\n"
24012401
" # Reactor for fd-based protocol handling\n"
24022402
" erlang.reactor = _erlang_impl.reactor\n"
2403+
" # Channel for bidirectional message passing\n"
2404+
" erlang.channel = _erlang_impl.channel\n"
2405+
" erlang.Channel = _erlang_impl.Channel\n"
2406+
" erlang.ChannelClosed = _erlang_impl.ChannelClosed\n"
2407+
" erlang.reply = _erlang_impl.reply\n"
24032408
" # Make erlang behave as a package for 'import erlang.reactor' syntax\n"
24042409
" erlang.__path__ = [priv_dir]\n"
24052410
" sys.modules['erlang.reactor'] = erlang.reactor\n"
2411+
" sys.modules['erlang.channel'] = erlang.channel\n"
24062412
" return True\n"
24072413
" except ImportError as e:\n"
24082414
" import sys\n"

0 commit comments

Comments
 (0)