In the Singleton problem, you implemented the pattern using __new__. That implementation has a race condition: two threads can simultaneously find _instance is None, both proceed past the check, and both create an instance — breaking the Singleton guarantee.
Implement a thread-safe ThreadSafeSingleton class that:
threading.Lock to protect instance creationThreadSafeSingleton(), even under concurrent accessreset() as a classmethod to clear the stored instance (for testing only)Constraints:
__new____new__)threading.RLock, threading.Semaphore, or any other primitive — use threading.Lockreset() does not need to acquire the lock (it is only called from single-threaded test code)