Debian Codegraph @

test/threads-test.py

raw symbols SCIP
1 import threading
2 import sys
3 import numpy as np
4
5 # Disable the @profile decorator if none has been declared.
6
7 try:
8 # Python 2
9 import __builtin__ as builtins
10 except ImportError:
11 # Python 3
12 import builtins
13
14 try:
15 builtins.profile
16 except AttributeError:
17 # No line profiler, provide a pass-through version
18 def profile(func):
19 return func
20
21 builtins.profile = profile
22
23
24 class MyThread(threading.Thread):
25 @profile
26 def run(self):
27 z = 0
28 z = np.random.uniform(0, 100, size=2 * 5000)
29 # print("thread1")
30
31
32 class MyThread2(threading.Thread):
33 @profile
34 def run(self):
35 z = 0
36 for i in range(5000 // 2):
37 z += 1
38 # print("thread2")
39
40
41 use_threads = True
42 # use_threads = False
43
44 if use_threads:
45 for i in range(10000):
46 t1 = MyThread()
47 t2 = MyThread2()
48 t1.start()
49 t2.start()
50 t1.join()
51 t2.join()
52 else:
53 t1 = MyThread()
54 t1.run()
55 t2 = MyThread2()
56 t2.run()