Thread Handling In Python Code