diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
commit | 6e2b99a0870e467e35c8b4b95aeb1e665dded413 (patch) | |
tree | 1e4b4d000c6b53b93a35b5446dc774d4799c987c /plot_exps.py | |
parent | 9bcbb4048cd82ea11ed469731eae95d808b99449 (diff) |
Many bugfixes motivated by some end-to-end testing.
Diffstat (limited to 'plot_exps.py')
-rwxr-xr-x | plot_exps.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/plot_exps.py b/plot_exps.py index 8fbef99..49cc729 100755 --- a/plot_exps.py +++ b/plot_exps.py | |||
@@ -5,6 +5,7 @@ import matplotlib.pyplot as plot | |||
5 | import os | 5 | import os |
6 | import shutil as sh | 6 | import shutil as sh |
7 | import sys | 7 | import sys |
8 | import traceback | ||
8 | from collections import namedtuple | 9 | from collections import namedtuple |
9 | from optparse import OptionParser | 10 | from optparse import OptionParser |
10 | from parse.col_map import ColMap,ColMapBuilder | 11 | from parse.col_map import ColMap,ColMapBuilder |
@@ -83,6 +84,15 @@ def plot_by_variable(details): | |||
83 | 84 | ||
84 | plot.savefig(details.out, format=OUT_FORMAT) | 85 | plot.savefig(details.out, format=OUT_FORMAT) |
85 | 86 | ||
87 | return True | ||
88 | |||
89 | def plot_wrapper(details): | ||
90 | '''Wrap exceptions in named method for printing in multiprocessing pool.''' | ||
91 | try: | ||
92 | return plot_by_variable(details) | ||
93 | except: | ||
94 | traceback.print_exc() | ||
95 | |||
86 | def plot_dir(data_dir, out_dir, force): | 96 | def plot_dir(data_dir, out_dir, force): |
87 | sys.stderr.write("Reading data...\n") | 97 | sys.stderr.write("Reading data...\n") |
88 | dir_map = DirMap.read(data_dir) | 98 | dir_map = DirMap.read(data_dir) |
@@ -102,11 +112,24 @@ def plot_dir(data_dir, out_dir, force): | |||
102 | if force or not os.path.exists(details.out): | 112 | if force or not os.path.exists(details.out): |
103 | plot_details += [details] | 113 | plot_details += [details] |
104 | 114 | ||
115 | if not plot_details: | ||
116 | return | ||
117 | |||
105 | procs = min(len(plot_details), cpu_count()/2) | 118 | procs = min(len(plot_details), cpu_count()/2) |
106 | pool = Pool(processes=procs) | 119 | pool = Pool(processes=procs) |
107 | enum = pool.imap_unordered(plot_by_variable, plot_details) | 120 | enum = pool.imap_unordered(plot_wrapper, plot_details) |
108 | for i, _ in enumerate(enum): | 121 | |
109 | sys.stderr.write('\r {0:.2%}'.format(float(i)/num_plots)) | 122 | try: |
123 | for i, _ in enumerate(enum): | ||
124 | sys.stderr.write('\r {0:.2%}'.format(float(i)/num_plots)) | ||
125 | pool.close() | ||
126 | except: | ||
127 | pool.terminate() | ||
128 | traceback.print_exc() | ||
129 | raise Exception("Failed plotting!") | ||
130 | finally: | ||
131 | pool.join() | ||
132 | |||
110 | sys.stderr.write('\n') | 133 | sys.stderr.write('\n') |
111 | 134 | ||
112 | def main(): | 135 | def main(): |