# Race Condition

say it: **“RAYS kun-DISH-un”** **/ˈreɪs kənˈdɪʃən/**

A bug where the result depends on which thread gets there first.

## What is a **race condition**?

A **race condition** is a bug where the result depends on which of two threads gets there first, like two people buying the last ticket at the same moment. A lock makes them take turns.

```python
import threading

tickets_left = 1
lock = threading.Lock()

def buy_ticket():
    global tickets_left
    with lock:                 # only one buyer at a time
        if tickets_left > 0:
            tickets_left -= 1
```

Level: Freelancer · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=4)

Updated: November 17, 2026

## In other subjects

- [Race Condition in C#](https://www.ask-codey.com/glossary/race-condition-c-sharp)
- [Race Condition in Database](https://www.ask-codey.com/glossary/race-condition-database)
- [Race Condition in Java](https://www.ask-codey.com/glossary/race-condition-java)

Source: https://www.ask-codey.com/glossary/race-condition
