forked from ijl/orjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread
More file actions
executable file
·58 lines (41 loc) · 1.17 KB
/
Copy paththread
File metadata and controls
executable file
·58 lines (41 loc) · 1.17 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
55
56
57
58
#!/usr/bin/env python3
import sys
import traceback
from concurrent.futures import ThreadPoolExecutor
from operator import itemgetter
from threading import get_ident
import orjson
DATA = sorted(
[
{
"id": i,
"name": "90as90ji0123ioj2390as90as90",
"body": "哈哈89asu89as😊89as9as90jas-😋0apjzxiojzx89hq23n",
"score": 901290129.1,
"bool": True,
"int": 9832,
"none": None,
}
for i in range(10)
],
key=itemgetter("id"),
)
STATUS = 0
TEST_MESSAGE = "thread test running..."
sys.stdout.write(TEST_MESSAGE)
sys.stdout.flush()
def test_func(n):
try:
assert sorted(orjson.loads(orjson.dumps(DATA)), key=itemgetter("id")) == DATA
except Exception:
STATUS = 1
traceback.print_exc()
print("thread %s: %s dumps, loads ERROR" % (get_ident(), n))
with ThreadPoolExecutor(max_workers=4) as executor:
executor.map(test_func, range(200000), chunksize=1000)
executor.shutdown(wait=True)
if STATUS == 0:
sys.stdout.write(f"\r{TEST_MESSAGE} ok\n")
else:
sys.stdout.write(f"\r{TEST_MESSAGE} error\n")
sys.exit(STATUS)