The Python community is finding new, creative uses for context managers. Some examples from the standard library are: Managing transactions in the sqlite3 module—see “Using the connection as a context manager”. Safely handling locks, conditions, and semaphores—as described in the threading module documentation. Setting up custom environments for arithmetic operations with Decimal objects—see the decimal.localcontext documentation. Patching objects for testing—see the unittest.mock.patch function.