How to Lock a Function Across Processes with a Decorator in Python

Sometimes several processes can call the same function at once, even though its logic is completely unsuited to that. One worker changes the password for an external system, another does exactly the same thing, and a third is trying to log in. Everyone meant well, but now nobody knows the current password XD. A similar problem comes up when refreshing shared data, generating the same report, or modifying a file. If these operations get in each other’s way, we get a classic race condition: a race where the winner sometimes turns out to be an error message. ...

October 8, 2026 · 6 min · SpaceShaman