Skip to content

v2.1.0 - Async Task API

Latest

Choose a tag to compare

@benoitc benoitc released this 12 Mar 12:28
· 118 commits to main since this release

Added

  • Async Task API - uvloop-inspired task submission from Erlang

    • py_event_loop:run/3,4 - Blocking run of async Python functions
    • py_event_loop:create_task/3,4 - Non-blocking task submission with reference
    • py_event_loop:await/1,2 - Wait for task result with timeout
    • py_event_loop:spawn_task/3,4 - Fire-and-forget task execution
    • Thread-safe submission via enif_send (works from dirty schedulers)
    • See Async Task API docs
  • erlang.spawn_task(coro) - Spawn async tasks from sync and async contexts

    • Works where asyncio.get_running_loop() fails
    • Returns asyncio.Task for optional await/cancel
  • Explicit Scheduling API - Control dirty scheduler release from Python

    • erlang.schedule(callback, *args) - Release scheduler, continue via Erlang callback
    • erlang.schedule_py(module, func, args, kwargs) - Release scheduler, continue in Python
    • erlang.consume_time_slice(percent) - Check if NIF time slice exhausted
    • ScheduleMarker type for cooperative long-running tasks
  • Distributed Python Execution - Run Python across Erlang nodes

Changed

  • Event Loop Performance
    • Growable pending queue (256 to 16384)
    • Snapshot-detach pattern to reduce mutex contention
    • Callable cache (64 slots) avoids PyImport/GetAttr per task
    • Task wakeup coalescing

Fixed

  • ensure_venv always installs deps, even if venv exists
  • erlang.sleep() timing in sync context
  • time() returns fresh value when loop not running
  • Handle pooling bugs in ErlangEventLoop
  • Task wakeup race causing batch task stalls