Two threads that change the same data can overwrite each other’s work. The result depends on exactly how their steps interleave, which the scheduler decides, and so the bug appears sometimes and vanishes when you look for it. That is a race condition, and it is the most important danger of threads. In this lesson you build a race on purpose, in a way that happens every time, then remove it with a lock, and learn the mistake that turns a lock into a deadlock.
More lessons in Complete Python Programming