99Written by Robert Cimrman
1010"""
1111
12+ import multiprocessing as mp
1213import 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.
2814
2915import matplotlib .pyplot as plt
16+ import numpy as np
3017
3118# Fixing random state for reproducibility
3219np .random .seed (19680801 )
@@ -90,13 +77,10 @@ def __call__(self, pipe):
9077
9178class NBPlot (object ):
9279 def __init__ (self ):
93- self .plot_pipe , plotter_pipe = Pipe ()
80+ self .plot_pipe , plotter_pipe = mp . Pipe ()
9481 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 )
10084 self .plot_process .start ()
10185
10286 def plot (self , finished = False ):
@@ -117,4 +101,6 @@ def main():
117101
118102
119103if __name__ == '__main__' :
104+ if plt .get_backend () == "MacOSX" :
105+ multiprocessing .set_start_method ("forkserver" )
120106 main ()
0 commit comments