Behavior-Oriented Concurrency for Python

· coding · Source ↗

TLDR

  • bocpy brings behavior-oriented concurrency to Python via cowns and @when behaviors, eliminating explicit locks and condition variables.

Key Takeaways

  • Cowns (concurrent-owned variables) enforce single-interpreter access using Python’s cross-interpreter data API, enabling safe multi-interpreter shared state.
  • @when decorator declares resource dependencies per behavior; the runtime schedules execution automatically once all required cowns are free.
  • Declaration order determines scheduling priority, so cook_omelette runs only after all ingredient prep behaviors complete, without manual synchronization.
  • Built-in Matrix class stores dense float64 data in C memory outside the Python heap, enabling zero-copy cown sharing across subinterpreters.
  • Erlang-style send/receive with selective matching and timeout callbacks provides lock-free cross-interpreter messaging backed by a C concurrent queue.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN