def assertSafeIter(self, method, interval=0.01, size=10000):
    from threading import Thread, Event
    from time import sleep
    x = LRUCache(size)
    x.update(zip(range(size), range(size)))

    class Burglar(Thread):

        def __init__(self, cache):
            self.cache = cache
            self.__is_shutdown = Event()
            self.__is_stopped = Event()
            Thread.__init__(self)

        def run(self):
            while (not self.__is_shutdown.isSet()):
                try:
                    self.cache.data.popitem(last=False)
                except KeyError:
                    break
            self.__is_stopped.set()

        def stop(self):
            self.__is_shutdown.set()
            self.__is_stopped.wait()
            self.join(THREAD_TIMEOUT_MAX)
    burglar = Burglar(x)
    burglar.start()
    try:
        for _ in getattr(x, method)():
            sleep(0.0001)
    finally:
        burglar.stop()
def assertSafeIter(self, method, interval=0.01, size=10000):
    from threading import Thread, Event
    from time import sleep
    x = LRUCache(size)
    x.update(zip(range(size), range(size)))

    class Burglar(Thread):

        def __init__(self, cache):
            self.cache = cache
            self.__is_shutdown = Event()
            self.__is_stopped = Event()
            Thread.__init__(self)

        def run(self):
            while (not self.__is_shutdown.isSet()):
                try:
                    self.cache.data.popitem(last=False)
                except KeyError:
                    break
            self.__is_stopped.set()

        def stop(self):
            self.__is_shutdown.set()
            self.__is_stopped.wait()
            self.join(THREAD_TIMEOUT_MAX)
    burglar = Burglar(x)
    burglar.start()
    try:
        for _ in getattr(x, method)():
            sleep(0.0001)
    finally:
        burglar.stop()