Skip to content

Commit 440e233

Browse files
committed
BOCpy example, fix code formatting
1 parent b6c3afb commit 440e233

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

  • content/posts
    • language-summit-2026-free-threading-post-era
    • language-summit-2026-macos-python
    • language-summit-2026-namespaces

‎content/posts/language-summit-2026-free-threading-post-era/index.md‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,46 @@ Providing a scheduler with a program written with the above constraints gets you
6161

6262
Some examples of programs written using locks and threads were then transformed into programs using the BOC model, such as two bank accounts transferring money between them and printing the results:
6363

64-
There are [many more examples available on GitHub](https://github.com/microsoft/bocpy/tree/main/examples). This proof of concept, implemented using subinterpreters, is available for anyone to try: [bocpy](https://microsoft.github.io/bocpy), available on the [Python Package Index](https://pypi.org/project/bocpy):
64+
```python
65+
from bocpy import Cown, wait, when
66+
67+
class Account:
68+
def __init__(self, name: str, balance: float):
69+
"""Initialize an account with a starting balance."""
70+
self.name = name
71+
self.balance = balance
72+
73+
def __repr__(self) -> str:
74+
"""Return a readable representation for debugging."""
75+
return f"Account(name='{self.name}', balance={self.balance})"
76+
77+
78+
def atomic_transfer(src: Cown[Account], dst: Cown[Account], amount: float):
79+
"""Move funds from ``src`` to ``dst`` if both are unfrozen and funded."""
80+
@when(src, dst)
81+
def do_transfer(src: Cown[Account], dst: Cown[Account], amount=amount):
82+
src_account = src.value
83+
dst_account = dst.value
84+
if src_account.balance > amount:
85+
src_account.balance -= amount
86+
dst_account.balance += amount
87+
88+
def check_balance(message: str, account: Cown[Account]):
89+
"""Log the current balance of the provided account."""
90+
@when(account)
91+
def do_check(account: Cown[Account], message=message):
92+
print(message, account.value)
93+
94+
alice = Cown(Account("Alice", 100))
95+
bob = Cown(Account("Bob", 0))
96+
97+
check_balance("src (before transfer):", alice)
98+
check_balance("dst (before transfer):", bob)
99+
atomic_transfer(alice, bob, 10)
100+
wait()
101+
```
65102

103+
There are [many more examples available on GitHub](https://github.com/microsoft/bocpy/tree/main/examples). This proof of concept, implemented using subinterpreters, is available for anyone to try: [bocpy](https://microsoft.github.io/bocpy), available on the [Python Package Index](https://pypi.org/project/bocpy):
66104

67105
Checking bocpy against their own criteria of simplicity, safety, and performance: bocpy is simple, as can be seen in the above examples. On the safety front, bocpy today runs in “stable Python”, and for this reason only isolation has been implemented so far. “We don’t yet have ownership, you can’t implement [ownership] as a third-party library”, as this would require changes to the runtime. Performance is “good for programs that aren’t communication dominated” due to “communication being expensive for subinterpreters”.
68106

‎content/posts/language-summit-2026-macos-python/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tags: [language-summit, language-summit-2026]
77
published: true
88
---
99

10-
Ned Deily, the macOS expert and release manager, shared that this was the first time discussing this topic in 15 years of Python Language Summits.
10+
Ned Deily, the macOS and release expert, shared that this was the first time discussing this topic in 15 years of Python Language Summits.
1111

1212
<figure>
1313

‎content/posts/language-summit-2026-namespaces/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Steering Council member and Release Manager Pablo Galindo Salgado opened the Lan
1919

2020
The issue manifests as seemingly random `AttributeError` exceptions from modules like `json`, `math`, or `http` for names you know are correct. Why is the standard library suddenly raising errors?
2121

22+
```console
2223
$ cat game.py
2324
import random
2425
if int(input("Pick a number 1-10")) == random.randint(1, 10):
@@ -32,6 +33,7 @@ AttributeError: module 'random' has no attribute 'randint' (???)
3233

3334
The issue is usually that a module is “shadowing” the standard library module from a higher-precedence location in `sys.path`, such as your current working directory or a directory on `PYTHONPATH`. There is probably a file named `json.py` or `math.py` in your project, and that module takes precedence over the standard library module of the same name, which is only noticed once you start using the module elsewhere in your project.
3435

36+
```console
3537
$ ls
3638
game.py random.py
3739

0 commit comments

Comments
 (0)