Python Isolates: Multi-Core Concurrency & Isolate.run()
Because standard Dart code runs on a single thread, heavy CPU-bound work (like parsing 50MB JSON, resizing images, or calculating cryptographic hashes) will freeze the event loop and cause UI frame drops. **Isolates** are separate memory-isolated threads that run concurrently on multiple CPU cores. In Dart 2.19+, **`Isolate.run()`** allows executing background work with zero boilerplate.
"Standard async code is one chef juggling multiple cooking pots in a single kitchen; an Isolate is hiring a second chef in a completely separate prep kitchen down the hall who does heavy chopping and passes the sliced vegetables through a serving hatch."
Deep Dive: How It Works
Isolated Memory: Isolates share NO mutable memory. State is passed between isolates by value copying (or zero-copy transfer for byte buffers).
`Isolate.run()`: Modern high-level API that spawns a worker, runs a computation function, transfers the result, and tears down the isolate automatically.
Message Passing: Low-level isolates communicate via `SendPort` and `ReceivePort` message channels.
Syntax Blueprint
// Offload heavy CPU work to another core
final result = await Isolate.run(() {
return computeHeavyPrimes(1000000);
});Isolate.run spawning a background worker on another CPU core.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Trying to access enclosing class state or global variables mutated inside an isolate.Why it happens: Isolates have completely separate memory heaps; mutations inside an isolate do not affect the main isolate.
How to fix: Return the computed result from the isolate callback.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Run Background Isolate Task
Define top-level `int computeProduct(int n) => n * 10;`.
In `main() async`, call `final val = await Isolate.run(() => computeProduct(42));`.
Print `Isolate Result: $val`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.