thread local data thread local data in some situations each thread requires its own copy of the data it is working withthis means that the shared (heapmemory is difficult to use as it is inherently shared between all threads to overcome this python provides concept known as thread-local data thread-local data is data whose values are associated with thread rather than with the shared memory this idea is illustrated belowto create thread-local data it is only necessary to create an instance of threading local (or subclass of thisand store attributes into it the instances will be thread specificmeaning that one thread will not see the values stored by another thread for examplefrom threading import threadlocalcurrentthread from random import randint def show_value(data)tryval data value except attributeerrorprint(currentthread(nameno value yet'elseprint(currentthread(namevalue ='valdef worker(data)show_value(datadata value randint( show_value(dataprint(currentthread(namestarting'local_data local(show_value(local_data