Repository navigation
Update multiprocess.py #6637
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
Closed
Closed
Update multiprocess.py #6637
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
57cde80
Update multiprocess.py
Thomas00010111 ae16ed7
Update multiprocess.py
Thomas00010111 82f7552
Update multiprocess.py
Thomas00010111 77b2a35
Update multiprocess.py
Thomas00010111 cb408db
Update multiprocess.py
Thomas00010111 764cd51
Update multiprocess.py
Thomas00010111 da94362
Update multiprocess.py
Thomas00010111 54d381c
Update multiprocess.py
Thomas00010111 8bb230d
Update multiprocess.py
Thomas00010111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,8 @@ | |
| import numpy as np | ||
|
|
||
| import matplotlib | ||
| matplotlib.use('GtkAgg') | ||
| matplotlib.use('TkAgg') | ||
| import matplotlib.pyplot as plt | ||
| import gobject | ||
|
|
||
|
|
||
| class ProcessPlotter(object): | ||
|
|
@@ -21,35 +20,33 @@ def __init__(self): | |
| def terminate(self): | ||
| plt.close('all') | ||
|
|
||
| def poll_draw(self): | ||
| def call_back(self): | ||
| while 1: | ||
| if not self.pipe.poll(): | ||
| break | ||
|
|
||
| def call_back(): | ||
| while 1: | ||
| if not self.pipe.poll(): | ||
| break | ||
| command = self.pipe.recv() | ||
|
|
||
| command = self.pipe.recv() | ||
| if command is None: | ||
| self.terminate() | ||
| return False | ||
|
|
||
| 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') | ||
|
|
||
| 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 | ||
| self.fig.canvas.draw() | ||
|
Member
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. It is better to use |
||
| return True | ||
|
|
||
| def __call__(self, pipe): | ||
| print('starting plotter...') | ||
|
|
||
| self.pipe = pipe | ||
| self.fig, self.ax = plt.subplots() | ||
| self.gid = gobject.timeout_add(1000, self.poll_draw()) | ||
| timer = self.fig.canvas.new_timer(interval=1000) | ||
| timer.add_callback(self.call_back) | ||
| timer.start() | ||
|
|
||
| print('...done') | ||
| plt.show() | ||
|
|
@@ -78,7 +75,7 @@ def main(): | |
| for ii in range(10): | ||
| pl.plot() | ||
| time.sleep(0.5) | ||
| raw_input('press Enter...') | ||
|
|
||
| pl.plot(finished=True) | ||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using canvas API now, this might be portable enough to not require setting a specific backend at all.