Example #1
0
def test_request_cached_property():
    class Foo(object):
        @request_cached_property
        def bar(self):
            return 5

    name = __name__ + '.bar'
    foo = Foo()
    assert threadlocal.get(name) is None
    assert 5 == foo.bar
    assert 5 == threadlocal.get(name)
    threadlocal.set(name, 6)
    assert 6 == foo.bar
    assert 6 == Foo().bar  # cache is shared between instances
Example #2
0
def test_request_cached_property():
    class Foo(object):
        @request_cached_property
        def bar(self):
            return 5

    name = __name__ + '.bar'
    foo = Foo()
    assert threadlocal.get(name) is None
    assert 5 == foo.bar
    assert 5 == threadlocal.get(name)
    threadlocal.set(name, 6)
    assert 6 == foo.bar
    assert 6 == Foo().bar  # cache is shared between instances
Example #3
0
    def _init(self, session, raise_errors):
        self.session = session
        self.raise_errors = raise_errors
        self.results = {
            'running': True,
            'completed': False,
            'categories': defaultdict(lambda: defaultdict(int))
        }

        # note: this will get cleared after request_cached_context object is released.
        assert not threadlocal.get('currently_running_email_daemon')
        threadlocal.set('currently_running_email_daemon', self)
Example #4
0
 def poll(self):
     """empty method which exists only to help keep WebSockets alive"""
     log.debug('sideboard.poll by user {}', threadlocal.get('username'))
Example #5
0
 def index(self):
     return threadlocal.get('username')
Example #6
0
 def _currently_running_daemon_on_this_thread(cls):
     return threadlocal.get('currently_running_email_daemon')
Example #7
0
 def with_caching(self):
     val = threadlocal.get(name)
     if val is None:
         val = func(self)
         threadlocal.set(name, val)
     return val
Example #8
0
 def with_caching(self):
     val = threadlocal.get(name)
     if val is None:
         val = func(self)
         threadlocal.set(name, val)
     return val