From 57cde8022ecd91d8be7ff5bc98a2107695ed9033 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Thu, 23 Jun 2016 14:09:22 -0700 Subject: [PATCH 1/9] Update multiprocess.py --- examples/misc/multiprocess.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 510e9001fa3e..be2735e0fa80 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -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): @@ -42,14 +41,16 @@ def call_back(): self.fig.canvas.draw() return True - return call_back + return call_back() 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.poll_draw) + timer.start() print('...done') plt.show() @@ -79,6 +80,7 @@ def main(): pl.plot() time.sleep(0.5) raw_input('press Enter...') +# input('press Enter...') #Python3 pl.plot(finished=True) if __name__ == '__main__': From ae16ed76bf22add42a48b3d59f60bca8af95f9a5 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Thu, 23 Jun 2016 14:37:54 -0700 Subject: [PATCH 2/9] Update multiprocess.py --- examples/misc/multiprocess.py | 37 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index be2735e0fa80..e470efa9933d 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -20,28 +20,24 @@ 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() + return True def __call__(self, pipe): print('starting plotter...') @@ -49,7 +45,7 @@ def __call__(self, pipe): 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') @@ -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__': From 82f75522a572dbe0571b6362b692ae4c261e1250 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Fri, 24 Jun 2016 08:53:46 -0700 Subject: [PATCH 3/9] Update multiprocess.py --- examples/misc/multiprocess.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index e470efa9933d..4a9ea95bf495 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -6,9 +6,7 @@ import time from multiprocessing import Process, Pipe import numpy as np - import matplotlib -matplotlib.use('TkAgg') import matplotlib.pyplot as plt @@ -21,7 +19,7 @@ def terminate(self): plt.close('all') def call_back(self): - while 1: + while True: if not self.pipe.poll(): break From 77b2a357e261d1909c51db9f460d8cb0d18514ce Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Sat, 25 Jun 2016 12:04:45 -0700 Subject: [PATCH 4/9] Update multiprocess.py --- examples/misc/multiprocess.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 4a9ea95bf495..5f276392ed84 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -7,6 +7,10 @@ from multiprocessing import Process, Pipe import numpy as np import matplotlib +# not all backends may allow safe plotting from multiple threads +# you can select a specific backend by uncommenting the line below +# and update the selected backend as needed +# matplotlib.use('QT5Agg') import matplotlib.pyplot as plt From cb408dbe13677a2e4e34cd9663f10e6a1acd1973 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Sun, 26 Jun 2016 15:02:31 -0700 Subject: [PATCH 5/9] Update multiprocess.py --- examples/misc/multiprocess.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 5f276392ed84..0394d655cd34 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -81,4 +81,11 @@ def main(): pl.plot(finished=True) if __name__ == '__main__': + # The default way to start a process on OSX ('fork') + # does not work well with many gui frameworks on OSX + # if you use Python 3.4 or later you can uncomment the + # two lines below to change the default start to + # forkserver. + # import multiprocessing as mp + # mp.set_start_method('forkserver') main() From 764cd5136f218572f6aec5ac1642c66a191ed6cb Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Sun, 26 Jun 2016 15:08:32 -0700 Subject: [PATCH 6/9] Update multiprocess.py --- examples/misc/multiprocess.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 0394d655cd34..c6a36e350ceb 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -5,6 +5,14 @@ from __future__ import print_function import time from multiprocessing import Process, Pipe +# The default way to start a process on OSX ('fork') +# does not work well with many gui frameworks on OSX +# if you use Python 3.4 or later you can uncomment the +# two lines below to change the default start to +# forkserver. +# import multiprocessing as mp +# mp.set_start_method('forkserver') + import numpy as np import matplotlib # not all backends may allow safe plotting from multiple threads @@ -81,11 +89,4 @@ def main(): pl.plot(finished=True) if __name__ == '__main__': - # The default way to start a process on OSX ('fork') - # does not work well with many gui frameworks on OSX - # if you use Python 3.4 or later you can uncomment the - # two lines below to change the default start to - # forkserver. - # import multiprocessing as mp - # mp.set_start_method('forkserver') main() From da94362cf0617610787e0144291d097a025b1c79 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Mon, 27 Jun 2016 10:57:31 -0700 Subject: [PATCH 7/9] Update multiprocess.py --- examples/misc/multiprocess.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index c6a36e350ceb..0394d655cd34 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -5,14 +5,6 @@ from __future__ import print_function import time from multiprocessing import Process, Pipe -# The default way to start a process on OSX ('fork') -# does not work well with many gui frameworks on OSX -# if you use Python 3.4 or later you can uncomment the -# two lines below to change the default start to -# forkserver. -# import multiprocessing as mp -# mp.set_start_method('forkserver') - import numpy as np import matplotlib # not all backends may allow safe plotting from multiple threads @@ -89,4 +81,11 @@ def main(): pl.plot(finished=True) if __name__ == '__main__': + # The default way to start a process on OSX ('fork') + # does not work well with many gui frameworks on OSX + # if you use Python 3.4 or later you can uncomment the + # two lines below to change the default start to + # forkserver. + # import multiprocessing as mp + # mp.set_start_method('forkserver') main() From 54d381c2662baa2b4b24e6e431a45fcb88febaf8 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Wed, 29 Jun 2016 21:41:25 -0700 Subject: [PATCH 8/9] Update multiprocess.py --- examples/misc/multiprocess.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 0394d655cd34..5339afde7b66 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -13,7 +13,6 @@ # matplotlib.use('QT5Agg') import matplotlib.pyplot as plt - class ProcessPlotter(object): def __init__(self): self.x = [] @@ -26,7 +25,7 @@ def call_back(self): while True: if not self.pipe.poll(): break - + command = self.pipe.recv() if command is None: @@ -38,7 +37,7 @@ def call_back(self): self.y.append(command[1]) self.ax.plot(self.x, self.y, 'ro') - self.fig.canvas.draw() + self.fig.canvas.draw_idle() return True def __call__(self, pipe): @@ -52,14 +51,12 @@ def __call__(self, pipe): print('...done') plt.show() - - + class NBPlot(object): def __init__(self): self.plot_pipe, plotter_pipe = Pipe() self.plotter = ProcessPlotter() - self.plot_process = Process(target=self.plotter, - args=(plotter_pipe,)) + self.plot_process = Process(target=self.plotter, args=(plotter_pipe,)) self.plot_process.daemon = True self.plot_process.start() @@ -79,7 +76,7 @@ def main(): time.sleep(0.5) pl.plot(finished=True) - + if __name__ == '__main__': # The default way to start a process on OSX ('fork') # does not work well with many gui frameworks on OSX From 8bb230d7b312d78b1e4b7ca2f3a87072b854ea19 Mon Sep 17 00:00:00 2001 From: Thomas00010111 Date: Wed, 29 Jun 2016 21:51:16 -0700 Subject: [PATCH 9/9] Update multiprocess.py --- examples/misc/multiprocess.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/misc/multiprocess.py b/examples/misc/multiprocess.py index 5339afde7b66..38a67507b4ff 100644 --- a/examples/misc/multiprocess.py +++ b/examples/misc/multiprocess.py @@ -7,12 +7,13 @@ from multiprocessing import Process, Pipe import numpy as np import matplotlib -# not all backends may allow safe plotting from multiple threads +# not all backends may allow safe plotting from multiple threads # you can select a specific backend by uncommenting the line below # and update the selected backend as needed # matplotlib.use('QT5Agg') import matplotlib.pyplot as plt + class ProcessPlotter(object): def __init__(self): self.x = [] @@ -25,7 +26,7 @@ def call_back(self): while True: if not self.pipe.poll(): break - + command = self.pipe.recv() if command is None: @@ -51,12 +52,14 @@ def __call__(self, pipe): print('...done') plt.show() - + + class NBPlot(object): def __init__(self): self.plot_pipe, plotter_pipe = Pipe() self.plotter = ProcessPlotter() - self.plot_process = Process(target=self.plotter, args=(plotter_pipe,)) + self.plot_process = Process(target=self.plotter, + args=(plotter_pipe,)) self.plot_process.daemon = True self.plot_process.start() @@ -76,7 +79,7 @@ def main(): time.sleep(0.5) pl.plot(finished=True) - + if __name__ == '__main__': # The default way to start a process on OSX ('fork') # does not work well with many gui frameworks on OSX