Create custom context managers for resource management and clean code.
Help me create context managers for: [DESCRIBE YOUR RESOURCES] Resources to manage: - [ ] File handles - [ ] Database connections - [ ] Network connections - [ ] Locks and synchronization - [ ] Temporary resources - [ ] Timer/profiling - [ ] Environment modifications - [ ] Transaction handling - [ ] Custom resources: [DESCRIBE] Provide: 1. Class-based context managers (__enter__/__exit__) 2. contextlib.contextmanager decorator approach 3. Async context managers (async with) 4. Nested context managers 5. ExitStack for dynamic management 6. Error handling in context managers 7. Reentrant context managers 8. Testing context managers 9. Type hints for context managers
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[DESCRIBE YOUR RESOURCES][DESCRIBE]