9
9
Written by Robert Cimrman
10
10
"""
11
11
12
+ import multiprocessing as mp
12
13
import time
13
- import numpy as np
14
-
15
- from multiprocessing import Process , Pipe
16
-
17
- # This example will likely not work with the native OSX backend.
18
- # Uncomment the following lines to use the qt5 backend instead.
19
- #
20
- # import matplotlib
21
- # matplotlib.use('qt5agg')
22
- #
23
- # Alternatively, with Python 3.4+ you may add the line
24
- #
25
- # import multiprocessing as mp; mp.set_start_method("forkserver")
26
- #
27
- # immediately after the ``if __name__ == "__main__"`` check.
28
14
29
15
import matplotlib .pyplot as plt
16
+ import numpy as np
30
17
31
18
# Fixing random state for reproducibility
32
19
np .random .seed (19680801 )
@@ -90,13 +77,10 @@ def __call__(self, pipe):
90
77
91
78
class NBPlot (object ):
92
79
def __init__ (self ):
93
- self .plot_pipe , plotter_pipe = Pipe ()
80
+ self .plot_pipe , plotter_pipe = mp . Pipe ()
94
81
self .plotter = ProcessPlotter ()
95
- self .plot_process = Process (
96
- target = self .plotter ,
97
- args = (plotter_pipe ,)
98
- )
99
- self .plot_process .daemon = True
82
+ self .plot_process = mp .Process (
83
+ target = self .plotter , args = (plotter_pipe ,), daemon = True )
100
84
self .plot_process .start ()
101
85
102
86
def plot (self , finished = False ):
@@ -117,4 +101,6 @@ def main():
117
101
118
102
119
103
if __name__ == '__main__' :
104
+ if plt .get_backend () == "MacOSX" :
105
+ multiprocessing .set_start_method ("forkserver" )
120
106
main ()
0 commit comments