File: thread

package info (click to toggle)
python-orjson 3.10.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,180 kB
  • sloc: ansic: 11,270; python: 6,658; sh: 135; makefile: 9
file content (55 lines) | stat: -rwxr-xr-x 1,172 bytes parent folder | download
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
#!/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:
        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(50000), 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)