-
Notifications
You must be signed in to change notification settings - Fork 12
/
JobManager.py
35 lines (24 loc) · 864 Bytes
/
JobManager.py
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
#!/usr/bin/python
"""JobManager: Helper class for running independent jobs in parallel,
catching and logging exceptions, and printing status messages."""
from multiprocessing import Pool
from env import *
from common import *
__author__ = "Lars Ahlzen"
__copyright__ = "(c) Lars Ahlzen 2011"
__license__ = "GPLv2"
def runJob(message, function, args):
console.printMessage(message)
try:
function(*args)
except Exception as ex:
console.printMessage('Failed: ' + message)
errorLog.log('Failed: ' + message, ex)
class JobManager():
def __init__(self, processes = NUM_THREADS):
self.pool = Pool(processes)
def addJob(self, message, function, args):
self.pool.apply_async(runJob, (message, function, args))
def finish(self):
self.pool.close()
self.pool.join()