forked from ramwin/python-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sorted_set.py
More file actions
54 lines (43 loc) · 1.01 KB
/
test_sorted_set.py
File metadata and controls
54 lines (43 loc) · 1.01 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Xiang Wang @ 2021-01-07 10:23:44
from ordered_set import OrderedSet
from threading import Thread
print("测试多线程导致sorted_set数据重复的问题")
import time
# 自己用的class有这个问题
# class A(object):
#
# def __init__(self):
# self.keys = []
#
# def run(self):
# print("我开始run啦")
# if 1 not in self.keys:
# print("两次都发现不存在哟")
# time.sleep(1)
# self.keys.append(1)
# print("我插入啦")
# print(self.keys)
# print("执行结束")
#
#
# def run():
# a = A()
# t1 = Thread(target=a.run)
# t1.start()
# t2 = Thread(target=a.run)
# t2.start()
# a.run()
#
#
def run():
s = OrderedSet()
threads = []
for i in range(1000):
threads.append(Thread(target=s.add, args=["test a very long key"]))
for t in threads:
t.start()
print(s)
if __name__ == "__main__":
run()