Skip to content

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
wants to merge 9 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update multiprocess.py
  • Loading branch information
Thomas00010111 authored Jun 23, 2016
commit ae16ed76bf22add42a48b3d59f60bca8af95f9a5
37 changes: 16 additions & 21 deletions examples/misc/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,32 @@ 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()
Copy link
Member

Choose a reason for hiding this comment

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

It is better to use draw_idle which defers the actually drawing until the GUI decides to really repaint the screen.

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 Expand Up @@ -79,8 +75,7 @@ def main():
for ii in range(10):
pl.plot()
time.sleep(0.5)
raw_input('press Enter...')
# input('press Enter...') #Python3

pl.plot(finished=True)

if __name__ == '__main__':
Expand Down