Detect Race conditions in Python