FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/unit/threading_test.py at boxplot-stat-transforms · phobson/matplotlib · GitHub
phobson
/
matplotlib
Public
forked from
matplotlib/matplotlib
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
unit
/
threading_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
73 lines (55 loc) · 1.74 KB
Breadcrumbs
matplotlib
/
unit
/
threading_test.py
Copy path
File metadata and controls
executable file
·
73 lines (55 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/python
"""
Test by Karen Tracey for threading problem reported in
http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg04819.html
and solved by JDH in git commit 175e3ec5bed9144.
"""
from
__future__
import
print_function
import
os
import
threading
import
traceback
import
numpy
as
np
from
matplotlib
.
backends
.
backend_agg
import
FigureCanvasAgg
as
FigureCanvas
from
matplotlib
.
figure
import
Figure
thread_count
=
8
max_iterations
=
50
exception_raised
=
False
def
png_thread
(
tn
):
png_fname
=
'out%d.png'
%
tn
vals
=
100
+
15
*
np
.
random
.
randn
(
10000
)
i
=
0
excp
=
None
global
exception_raised
while
not
exception_raised
and
i
<
max_iterations
:
i
+=
1
png_f
=
open
(
png_fname
,
'wb'
)
try
:
fig
=
Figure
()
ax
=
fig
.
add_subplot
(
111
)
ax
.
hist
(
vals
,
50
)
FigureCanvas
(
fig
).
print_png
(
png_f
)
except
Exception
as
excp
:
pass
png_f
.
close
()
if
excp
:
print
(
'png_thread %d failed on iteration %d:'
%
(
tn
,
i
))
print
(
traceback
.
format_exc
(
excp
))
exception_raised
=
True
else
:
print
(
'png_thread %d completed iteration %d.'
%
(
tn
,
i
))
os
.
unlink
(
png_fname
)
def
main
(
tc
):
threads
=
[]
for
i
in
range
(
tc
):
threads
.
append
(
threading
.
Thread
(
target
=
png_thread
,
args
=
(
i
+
1
,)))
for
t
in
threads
:
t
.
start
()
for
t
in
threads
:
t
.
join
()
if
not
exception_raised
:
msg
=
'Success! %d threads completed %d iterations with no exceptions raised.'
else
:
msg
=
'Failed! Exception raised before %d threads completed %d iterations.'
print
(
msg
%
(
tc
,
max_iterations
))
if
__name__
==
"__main__"
:
main
(
thread_count
)
Back
|
FazBrowse Home
|
New Git URL