Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a8bd774

Browse filesBrowse files
authored
Merge pull request #11320 from anntzer/update-multiprocess-example
Py3fy multiprocess example.
2 parents 8c8e1b5 + ac42faa commit a8bd774
Copy full SHA for a8bd774

File tree

Expand file treeCollapse file tree

1 file changed

+7
-21
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-21
lines changed

‎examples/misc/multiprocess_sgskip.py

Copy file name to clipboardExpand all lines: examples/misc/multiprocess_sgskip.py
+7-21Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,11 @@
99
Written by Robert Cimrman
1010
"""
1111

12+
import multiprocessing as mp
1213
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.
2814

2915
import matplotlib.pyplot as plt
16+
import numpy as np
3017

3118
# Fixing random state for reproducibility
3219
np.random.seed(19680801)
@@ -90,13 +77,10 @@ def __call__(self, pipe):
9077

9178
class 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

119103
if __name__ == '__main__':
104+
if plt.get_backend() == "MacOSX":
105+
multiprocessing.set_start_method("forkserver")
120106
main()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.