| 163 | |
| 164 | |
| 165 | def test_memoize_thread_local(): |
| 166 | class Counter(object): |
| 167 | def __init__(self, s): |
| 168 | self.val = s |
| 169 | |
| 170 | def inc(self): |
| 171 | self.val += 1 |
| 172 | return self.val |
| 173 | |
| 174 | @func.memoize(thread_local=True) |
| 175 | def get_counter(start): |
| 176 | return Counter(start) |
| 177 | |
| 178 | def th_inc(): |
| 179 | assert get_counter(0).inc() == 1 |
| 180 | assert get_counter(0).inc() == 2 |
| 181 | assert get_counter(10).inc() == 11 |
| 182 | assert get_counter(10).inc() == 12 |
| 183 | |
| 184 | th_inc() |
| 185 | |
| 186 | th = threading.Thread(target=th_inc) |
| 187 | th.start() |
| 188 | th.join() |
| 189 | |
| 190 | |
| 191 | def test_memoize_not_thread_safe(): |