Skip to main content

A @decorator for caching properties in classes in the thread-local storage.

Project description

@tls_property is a super-tiny library that will help you write thread-safe classes.

It’s acting like a @cached_property, but value will be cached only for current thread.

Garbage collecting is respected, @tls_property won’t mess up with it.

from some_library import NonThreadsafeSuperClient
from tls_property import tls_property

class SuperClientWrapper:
    def nonthreadsafe_client(self) -> NonThreadsafeSuperClient:
        return NonThreadsafeSuperClient()

Also, value reset supported via @tls_property del ete:

client = SuperClientWrapper()
del client.nonthreadsafe_client

Module works on Python == 2.7 and Python ~= 3.4.


pip install tls-property


Public Domain: CC0 1.0 Universal.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tls-property-1.1.0.tar.gz (2.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page