Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,7 +19,13 @@ | ||
# Uncomment the following lines to use the qt5 backend instead. | ||
# | ||
# import matplotlib | ||
# 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 | ||
@@ -43,30 +49,26 @@ def __init__(self): | ||
def terminate(self): | ||
plt.close('all') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Huh, what was the point of this? Some kind of closure effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. not sure, but AFAICT it works without it... | ||
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.call_back) | ||
timer.start() | ||
print('...done') | ||