1
2
3
4
5
6 '''
7 Asynchronous local execution.
8
9 Supports multicore architectures.
10 '''
11
12 from Bio.PopGen.Async import Async, FileRetriever
13
14 import thread
15
17 '''Execution on Local machine.
18 '''
19
21 '''Constructor.
22
23 parameters:
24 num_cores - Number of cores (for multiprocessor machines,
25 multiply accordingly)
26 '''
27 Async.__init__(self)
28 self.num_cores = num_cores
29 self.cores_used = 0
30
32 '''Run program.
33
34 For parameters, please check Async.run_program.
35
36 Either runs a program if a core is available or
37 schedules it.
38 '''
39 self.access_ds.acquire()
40 self.waiting.append((id, hook, parameters, input_files))
41 if self.cores_used < self.num_cores:
42 self.cores_used += 1
43 thread.start_new_thread(self.start_work, ())
44 self.access_ds.release()
45
47 '''Starts work.
48
49 Thread initial point.
50 While there are tasks to be done, runs them.
51 The thread dies as soon as there is nothing waiting to be
52 executed.
53 '''
54 self.access_ds.acquire()
55 while (len(self.waiting) > 0):
56 id, hook, parameters, input_files = self.waiting[0]
57 del self.waiting[0]
58 self.running[id] = True
59 self.access_ds.release()
60 ret_code, output_files = hook.run_job(parameters, input_files)
61 self.access_ds.acquire()
62 del self.running[id]
63 self.done[id] = ret_code, output_files
64 self.cores_used -= 1
65 self.access_ds.release()
66