Mercurial > repos > peterjc > tmhmm_and_signalp
comparison tools/protein_analysis/seq_analysis_utils.py @ 3:f3b373a41f81
Migrated tool version 0.0.6 from old tool shed archive to new tool shed repository
| author | peterjc |
|---|---|
| date | Tue, 07 Jun 2011 18:05:13 -0400 |
| parents | bca9bc7fdaef |
| children | a290c6d4e658 |
comparison
equal
deleted
inserted
replaced
| 2:6901298ac16c | 3:f3b373a41f81 |
|---|---|
| 100 if os.path.isfile(f): | 100 if os.path.isfile(f): |
| 101 os.remove(f) | 101 os.remove(f) |
| 102 raise err | 102 raise err |
| 103 return files | 103 return files |
| 104 | 104 |
| 105 def run_jobs(jobs, threads): | 105 def run_jobs(jobs, threads, verbose=False): |
| 106 """Takes list of cmd strings, returns dict with error levels.""" | 106 """Takes list of cmd strings, returns dict with error levels.""" |
| 107 pending = jobs[:] | 107 pending = jobs[:] |
| 108 running = [] | 108 running = [] |
| 109 results = {} | 109 results = {} |
| 110 while pending or running: | 110 while pending or running: |
| 111 #print "%i jobs pending, %i running, %i completed" \ | |
| 112 # % (len(jobs), len(running), len(results)) | |
| 113 #See if any have finished | 111 #See if any have finished |
| 114 for (cmd, process) in running: | 112 for (cmd, process) in running: |
| 115 return_code = process.wait() | 113 return_code = process.poll() #non-blocking |
| 116 if return_code is not None: | 114 if return_code is not None: |
| 117 results[cmd] = return_code | 115 results[cmd] = return_code |
| 118 running = [(cmd, process) for (cmd, process) in running \ | 116 running = [(cmd, process) for (cmd, process) in running \ |
| 119 if cmd not in results] | 117 if cmd not in results] |
| 118 if verbose: | |
| 119 print "%i jobs pending, %i running, %i completed" \ | |
| 120 % (len(pending), len(running), len(results)) | |
| 120 #See if we can start any new threads | 121 #See if we can start any new threads |
| 121 while pending and len(running) < threads: | 122 while pending and len(running) < threads: |
| 122 cmd = pending.pop(0) | 123 cmd = pending.pop(0) |
| 124 if verbose: | |
| 125 print cmd | |
| 123 process = subprocess.Popen(cmd, shell=True) | 126 process = subprocess.Popen(cmd, shell=True) |
| 124 running.append((cmd, process)) | 127 running.append((cmd, process)) |
| 125 #Loop... | 128 #Loop... |
| 126 sleep(1) | 129 sleep(10) |
| 127 #print "%i jobs completed" % len(results) | 130 if verbose: |
| 131 print "%i jobs completed" % len(results) | |
| 128 assert set(jobs) == set(results) | 132 assert set(jobs) == set(results) |
| 129 return results | 133 return results |
