def __init__(self, collection=None, debug=0, max_threads=1, mode='threading'): """ Constructor. @type debug: int @param debug: The debug level. @type max_threads: int @param max_threads: The maximum number of concurrent threads. """ if mode == 'threading': self.job_cls = Thread elif mode == 'multiprocessing': self.job_cls = Process else: raise TypeError('invalid "mode" argument: ' + repr(mode)) if collection is None: self.collection = Pipeline(max_threads) else: self.collection = collection collection.set_max_working(max_threads) self.job_init_event = Event() self.job_started_event = Event() self.job_error_event = Event() self.job_succeeded_event = Event() self.job_aborted_event = Event() self.queue_empty_event = Event() self.debug = debug self.main_loop = None self._init()
def testMainLoop(self): lock = threading.Lock() data = {'sum': 0, 'randsum': 0} ml = MainLoop.MainLoop(Pipeline(), Process) nop = lambda x: None for i in range(12345): ml.enqueue(nop, name = 'test', times = 1, data = None) self.assertEqual(0, data['sum'])