FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
msgpack-python/test/uneeded_test_multithreading.py at main · msgpack/msgpack-python · GitHub
msgpack
msgpack-python
Repository navigation
Code
Issues
4
(4)
Pull requests
15
(15)
Discussions
Actions
Security and quality
2
(2)
Insights
Expand file tree
Breadcrumbs
msgpack-python
/
test
/
uneeded_test_multithreading.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (44 loc) · 1.42 KB
Breadcrumbs
msgpack-python
/
test
/
uneeded_test_multithreading.py
Copy path
File metadata and controls
51 lines (44 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
import
threading
from
concurrent
.
futures
import
ThreadPoolExecutor
from
msgpack
import
Packer
def
run_threaded
(
func
,
num_threads
=
8
,
pass_count
=
False
,
pass_barrier
=
False
,
outer_iterations
=
1
,
prepare_args
=
None
,
):
"""Runs a function many times in parallel"""
for
_
in
range
(
outer_iterations
):
with
ThreadPoolExecutor
(
max_workers
=
num_threads
)
as
tpe
:
if
prepare_args
is
None
:
args
=
[]
else
:
args
=
prepare_args
()
if
pass_barrier
:
barrier
=
threading
.
Barrier
(
num_threads
)
args
.
append
(
barrier
)
if
pass_count
:
all_args
=
[(
func
,
i
,
*
args
)
for
i
in
range
(
num_threads
)]
else
:
all_args
=
[(
func
,
*
args
)
for
i
in
range
(
num_threads
)]
try
:
futures
=
[]
for
arg
in
all_args
:
futures
.
append
(
tpe
.
submit
(
*
arg
))
finally
:
if
len
(
futures
)
<
num_threads
and
pass_barrier
:
barrier
.
abort
()
for
f
in
futures
:
f
.
result
()
def
test_multithread_packing
():
output
=
[]
test_data
=
"abcd"
*
10_000_000
packer
=
Packer
()
def
closure
(
b
):
data
=
packer
.
pack
(
test_data
)
output
.
append
(
data
)
b
.
wait
()
run_threaded
(
closure
,
num_threads
=
10
,
pass_barrier
=
True
,
pass_count
=
False
)
Back
|
FazBrowse Home
|
New Git URL