source: subversion/applications/rendering/toposm/JobManager.py @ 34399

Last change on this file since 34399 was 25435, checked in by ahlzen, 9 years ago

Minor refactoring and cleanup of the TopOSM code.

File size: 864 bytes
Line 
1#!/usr/bin/python
2
3"""JobManager: Helper class for running independent jobs in parallel,
4catching and logging exceptions, and printing status messages."""
5
6
7from multiprocessing import Pool
8
9from env import *
10from common import *
11
12__author__      = "Lars Ahlzen"
13__copyright__   = "(c) Lars Ahlzen 2011"
14__license__     = "GPLv2"
15
16
17def runJob(message, function, args):
18    console.printMessage(message)
19    try:
20        function(*args)
21    except Exception as ex:
22        console.printMessage('Failed: ' + message)
23        errorLog.log('Failed: ' + message, ex)
24
25class JobManager():
26    def __init__(self, processes = NUM_THREADS):
27        self.pool = Pool(processes)
28
29    def addJob(self, message, function, args):
30        self.pool.apply_async(runJob, (message, function, args))
31       
32    def finish(self):
33        self.pool.close()
34        self.pool.join()
35
Note: See TracBrowser for help on using the repository browser.