How Python deals with threads