Skip to content

Minor update to multiprocessing example. #10168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions examples/misc/multiprocess_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
# Uncomment the following lines to use the qt5 backend instead.
#
# import matplotlib
# matplotlib.use('qt5Agg')
# matplotlib.use('qt5agg')
#
# Alternatively, with Python 3.4+ you may add the line
#
# import multiprocessing as mp; mp.set_start_method("forkserver")
#
# immediately after the ``if __name__ == "__main__"`` check.

import matplotlib.pyplot as plt

Expand All @@ -43,30 +49,26 @@ def __init__(self):
def terminate(self):
plt.close('all')

def poll_draw(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, what was the point of this? Some kind of closure effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, but AFAICT it works without it...


def call_back():
while self.pipe.poll():
command = self.pipe.recv()
if command is None:
self.terminate()
return False
else:
self.x.append(command[0])
self.y.append(command[1])
self.ax.plot(self.x, self.y, 'ro')
self.fig.canvas.draw()
return True

return call_back
def call_back(self):
while self.pipe.poll():
command = self.pipe.recv()
if command is None:
self.terminate()
return False
else:
self.x.append(command[0])
self.y.append(command[1])
self.ax.plot(self.x, self.y, 'ro')
self.fig.canvas.draw()
return True

def __call__(self, pipe):
print('starting plotter...')

self.pipe = pipe
self.fig, self.ax = plt.subplots()
timer = self.fig.canvas.new_timer(interval=1000)
timer.add_callback(self.poll_draw())
timer.add_callback(self.call_back)
timer.start()

print('...done')
Expand Down