I’ve been using TypeScript in a side project recently and was learning about the JavaScript event loop. As a Pythonista, it made me think of the Python GIL. Both the event loop and the GIL are concurrency mechanisms, but they work very differently.

The GIL allows only one thread to execute Python bytecode at a time. This prevents true multi-threading: even though multiple threads can exist at the same time, they have to take turns executing Python bytecode. The GIL exists because CPython’s memory management isn’t thread safe.

The event loop is single-threaded by design: there is only one thread running JavaScript code. It uses an event-driven, non-blocking I/O model. Concurrency comes from the ability to pause and resume functions and handle I/O asynchronously.

Both the event loop and the GIL prevent multiple pieces of code from running simultaneously, but the GIL is a limitation whereas the event loop is a design choice.

Definitions