ThreadLocalStorage#
- class barecat.util.threading.ThreadLocalStorage(threadsafe)[source]#
Storage that lazily creates values and handles closing.
Encapsulates the common pattern of: - Lazily creating a value on first access using a factory - Closing the value when done - Optionally being thread-local (each thread gets its own value)
- Usage:
storage = ThreadLocalStorage(threadsafe=True)
# Get or create value sock = storage.get(make_socket)
# Close and clear storage.close()
- Parameters:
threadsafe (bool)