@@ -2759,35 +2759,77 @@ class gnuplotlib provides full power and flexibility, but for simple image-map
27592759 plot (* curves , ** jointOptions )
27602760
27612761
2762- def wait ():
2763- r'''Waits until the open interactive plot window is closed
2762+ def wait (* args ):
2763+ r'''Waits until the given interactive plot window(s) are closed
27642764
27652765 SYNOPSIS
27662766
27672767 import numpy as np
27682768 import gnuplotlib as gp
27692769
2770- gp. plot(np.arange(5))
2771-
2770+ ### Waiting for the global plot window
2771+ gp.plot(...)
27722772 # interactive plot pops up
2773-
27742773 gp.wait()
2775-
27762774 # We get here when the user closes the plot window
27772775
2776+
2777+ ### Waiting on some arbitrary plots
2778+ plot0 = gp.gnuplotlib(...)
2779+ plot1 = gp.gnuplotlib(...)
2780+ plot0.plot(...)
2781+ plot1.plot(...)
2782+ gp.wait(plot0,plot1)
2783+ # We get here when the user closes the plot windows
2784+
2785+
27782786 DESCRIPTION
27792787
2780- This applies to the global gnuplotlib object.
2788+ Wait for the interactive plot window(s) to be closed by the user. Without
2789+ any argument this applies to the global gnuplotlib object. Or the specific
2790+ plots to wait for can be given in arguments (in-line or as a single
2791+ iterable):
27812792
2782- It's not at all trivial to detect if a current plot window exists. If not,
2783- this function will end up waiting forever, and the user will need to Ctrl-C
2793+ - wait() waits on the global gnuplot object
2794+
2795+ - wait(plot0,plot1)
2796+ - wait((plot0,plot1),) both wait on the given gnuplotlib objects
2797+
2798+ It's not at all trivial to detect if a plot object has an open plot window.
2799+ If it does not, this function will end up waiting forever, and the user will
2800+ need to Ctrl-C
27842801
27852802 '''
27862803 global globalplot
2787- if not globalplot :
2788- raise GnuplotlibError ("There isn't a plot to wait on" )
27892804
2790- globalplot .wait ()
2805+ if len (args ) == 0 :
2806+ if not globalplot :
2807+ raise GnuplotlibError ("There isn't a plot to wait on" )
2808+ plots = (globalplot ,)
2809+ elif all (isinstance (p ,gnuplotlib ) for p in args ):
2810+ plots = args
2811+ elif len (args ) == 1 :
2812+ plots = args [0 ]
2813+ else :
2814+ raise Exception ("gnuplotlib.wait() takes an inline list of plots or a single list-of-plots argumnent. Got neither" )
2815+
2816+ if len (plots ) == 1 :
2817+ # Special-case if we have exactly one plot to wait on. Can avoid forking
2818+ # in this case, so I do that
2819+ plots [0 ].wait ()
2820+ return
2821+
2822+ # N plots
2823+ pids = [0 ] * len (plots )
2824+ for i ,plot in enumerate (plots ):
2825+ pid = os .fork ()
2826+ if pid == 0 :
2827+ # child
2828+ plot .wait ()
2829+ os ._exit (0 )
2830+ pids [i ] = pid
2831+ for pid in pids :
2832+ os .waitpid (pid ,0 )
27912833
27922834
27932835def add_plot_option (d ,
0 commit comments