-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample1.py
More file actions
35 lines (30 loc) · 774 Bytes
/
Copy pathexample1.py
File metadata and controls
35 lines (30 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# same as example1, but without explicit viztracer calls
import threading
import time
# if we don't run with gil_load, we just skip it
import gil_load
try:
gil_load.init()
gil_load.start()
use_gil_load = True
except RuntimeError:
use_gil_load = False
def some_computation():
total = 0
for i in range(1_000_000):
total += i
return total
thread1 = threading.Thread(target=some_computation)
thread2 = threading.Thread(target=some_computation)
def main(args=None):
thread1.start()
thread2.start()
time.sleep(0.2)
for thread in [thread1, thread2]:
thread.join()
if use_gil_load:
gil_load.stop()
stats = gil_load.get()
print(gil_load.format(stats))
if __name__ == "__main__":
main()