Package trac ::
Package util ::
Package tests ::
Module concurrency
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2010 Edgewall Software
4 # All rights reserved.
5 #
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://trac.edgewall.org/wiki/TracLicense.
9 #
10 # This software consists of voluntary contributions made by many
11 # individuals. For the exact contribution history, see the revision
12 # history and logs, available at http://trac.edgewall.org/log/.
13
14 import threading
15 import unittest
16
17 from trac .util .concurrency import ThreadLocal
18
19
21
23 local = ThreadLocal (a=1, b =2)
24 local.b = 3
25 local.c = 4
26 local_dict = [local.__dict__.copy()]
27 def f():
28 local.b = 5
29 local.d = 6
30 local_dict.append(local.__dict__.copy())
31 thread = threading.Thread(target=f)
32 thread.start ()
33 thread.join ()
34 self.assertEqual (dict(a=1, b =3, c =4), local_dict[0])
35 self.assertEqual (dict(a=1, b =5, d =6), local_dict[1])