#!/usr/bin/env python from __future__ import print_function, division import subprocess from os.path import splitext, split def run_fit(filename): head, tail = split(filename) root, ext = splitext(tail) output = root + '.hdf5' cmd = ["./fit", filename, "-o", output] subprocess.call(cmd) if __name__ == '__main__': import argparse from multiprocessing import Pool, cpu_count import signal import os parser = argparse.ArgumentParser("fit multiple zdab files") parser.add_argument("-j", "--jobs", type=int, default=None, help="number of jobs") parser.add_argument("filenames", nargs="+", help="zdab files") args = parser.parse_args() jobs = args.jobs if jobs is None: jobs = cpu_count() # see https://stackoverflow.com/questions/11312525/catch-ctrlc-sigint-and-exit-multiprocesses-gracefully-in-python handler = signal.signal(signal.SIGINT, signal.SIG_IGN) p = Pool(jobs) signal.signal(signal.SIGINT, handler) try: result = p.map_async(run_fit,args.filenames) result.get() except KeyboardInterrupt: print("ctrl-c caught. quitting...") p.terminate() os.killpg(os.getpgid(0),9) else: p.close() p.join() dm/tree/README?id=dd017644419ad1bb4966d0cec5b72e50ef920f0e'>treecommitdiff
path: root/README
blob: 76cfb88ba26869c8a6ee1cd6de4d8ca47dc36453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162