Four independent Python processes compute a live Julia fractal. Native NumPy does the numerical work. SwiftUI puts the result on screen.
Build with native libraries.
CPython and NumPy are built for iOS and bundled with the app. Your Python runs in native worker processes, with a direct path into your Swift application.
Four workers. One image.
Each worker computes a quarter of every frame. Swift combines the pixels into the animation. The app shows the actual process IDs and checks sample pixels against an independent calculation.
An unshipped iOS development preview. The recording runs locally in the iPadOS 26.5 simulator; its timings are not device benchmarks. iOS support is not included in the current commercial release.
iPadOS 26.5 simulator · 13 seconds · Recorded at normal speed. Four Python processes compute the animated fractal; the app displays their process IDs and frame timing.
The code behind the recording.
Swift dispatches one tile to each worker. Python computes those pixels with NumPy. These excerpts come from the app in the video.
Development-preview APIs. The app’s extension setup, Tile type, bundled-script loading, image assembly and lifecycle handling surround these excerpts; this is not a standalone app.
Swift · four workers
try PythonWorkerExtensions.configure(extensionPoint: .pythonWorker)
let pool = try await PythonProcessPool(workers: 4, blasThreads: 1)
// After loading fractal.py into each worker with pool.warmup(...):
let selectedFrame = frame
let result = try await withThrowingTaskGroup(of: Tile.self) { group in
for worker in 0..<4 {
group.addTask {
let json: String = try await pool.evalResult("render_tile(\(worker), \(selectedFrame))", worker: worker)
return try JSONDecoder().decode(Tile.self, from: Data(json.utf8))
}
}
var output: [Tile] = []
for try await tile in group { output.append(tile) }
return output.sorted { $0.worker < $1.worker }
}
Python · each worker’s tile
import numpy as np
def render_tile(worker, frame, size=640):
start = time.monotonic_ns()
rows = size // 4
phase = frame * 0.018
c = complex(-0.745 + 0.055 * np.sin(phase), 0.186 + 0.025 * np.cos(phase))
x = np.linspace(-1.55, 1.55, size)
y = np.linspace(-1.55, 1.55, size)[worker * rows:(worker + 1) * rows]
z = x[None, :] + 1j * y[:, None]
escaped = np.zeros(z.shape, dtype=np.int32)
active = np.ones(z.shape, dtype=bool)
for iteration in range(96):
z[active] = z[active] ** 2 + c
outside = active & (np.abs(z) > 2.0)
escaped[outside] = iteration + 1
active[outside] = False
The rest of the Python function checks sample pixels against an independent scalar calculation, colors the result, and returns RGBA bytes with the worker’s process ID.
From the command line
Watch the runtime work.
Real native runs, recorded so you can inspect the result.
Metal writes it. Python reads the same payload.
A GPU kernel writes 32 MiB. Python verifies the bytes with SHA-256 through a borrowed view. The run also checks four workers, 10,000 buffer reuse cycles, worker replacement and rejected stale ownership.
macOS · Apple M4 Pro · Development source. Recorded stdout replay; two excerpts preserve original timing. The final result is held for eight seconds. Timings describe this run.
Captured command
./examples --duplex-metal-ledger
Python calls Swift. Swift calls back into the same worker.
The recording checks three things: Swift returns the expected scores to Python; Python keeps computing while a Swift policy callback is suspended, then reads actual true and false results; and a Swift callback re-enters the original Python process and reads its private state.
Distinct host and worker PIDs, a random worker-local nonce, and exact Swift callback counts make those checks visible. The command fails if any check fails.
macOS · Development source. Recorded stdout replay at original timing; the final result is held for eight seconds.
Captured command
./examples --callbacks-control
These commands ran the examples executable built from the development source checkout. They are not terminal commands supplied by the current commercial package. Each run completed its own checks successfully.