def __init__(self, testdir, concurrency): self._log = multiprocessing.get_logger() self.testdir = testdir # seems needed for python 2.x to handle keyboard interrupt self._stop = multiprocessing.Event() self._async = concurrency > 1 if not self._async: self._pool = None global stop global ports stop = self._stop ports = PortAllocator() else: self._m = multiprocessing.managers.BaseManager() self._m.register('ports', PortAllocator) self._m.start() self._pool = multiprocessing.Pool(concurrency, self._pool_init, (self._m.address, )) self._report = SummaryReporter(testdir, concurrency > 1) self._log.debug('TestDispatcher started with %d concurrent jobs' % concurrency)
def __init__(self, testdir, concurrency): self._log = multiprocessing.get_logger() self.testdir = testdir # seems needed for python 2.x to handle keyboard interrupt self._stop = multiprocessing.Event() self._async = concurrency > 1 if not self._async: self._pool = None global stop global ports stop = self._stop ports = PortAllocator() else: self._m = multiprocessing.managers.BaseManager() self._m.register('ports', PortAllocator) self._m.start() self._pool = multiprocessing.Pool(concurrency, self._pool_init, (self._m.address,)) self._report = SummaryReporter(testdir, concurrency > 1) self._log.debug( 'TestDispatcher started with %d concurrent jobs' % concurrency)
class TestDispatcher(object): def __init__(self, testdir, concurrency): self._log = multiprocessing.get_logger() self.testdir = testdir # seems needed for python 2.x to handle keyboard interrupt self._stop = multiprocessing.Event() self._async = concurrency > 1 if not self._async: self._pool = None global stop global ports stop = self._stop ports = PortAllocator() else: self._m = multiprocessing.managers.BaseManager() self._m.register('ports', PortAllocator) self._m.start() self._pool = multiprocessing.Pool(concurrency, self._pool_init, (self._m.address, )) self._report = SummaryReporter(testdir, concurrency > 1) self._log.debug('TestDispatcher started with %d concurrent jobs' % concurrency) def _pool_init(self, address): global stop global m global ports stop = self._stop m = multiprocessing.managers.BaseManager(address) m.connect() ports = m.ports() def _dispatch_sync(self, test, cont): r = run_test(self.testdir, test, False) cont(r) return NonAsyncResult(r) def _dispatch_async(self, test, cont): return self._pool.apply_async(func=run_test, args=( self.testdir, test, ), callback=cont) def dispatch(self, test): index = self._report.add_test(test) def cont(r): if not self._stop.is_set(): self._log.debug('freeing port') self._log.debug('adding result') self._report.add_result(index, r, r == RESULT_TIMEOUT) self._log.debug('finish continuation') fn = self._dispatch_async if self._async else self._dispatch_sync return fn(test, cont) def wait(self): if self._async: self._pool.close() self._pool.join() self._m.shutdown() return self._report.end() def terminate(self): self._stop.set() if self._async: self._pool.terminate() self._pool.join() self._m.shutdown()
class TestDispatcher(object): def __init__(self, testdir, concurrency): self._log = multiprocessing.get_logger() self.testdir = testdir # seems needed for python 2.x to handle keyboard interrupt self._stop = multiprocessing.Event() self._async = concurrency > 1 if not self._async: self._pool = None global stop global ports stop = self._stop ports = PortAllocator() else: self._m = multiprocessing.managers.BaseManager() self._m.register('ports', PortAllocator) self._m.start() self._pool = multiprocessing.Pool(concurrency, self._pool_init, (self._m.address,)) self._report = SummaryReporter(testdir, concurrency > 1) self._log.debug( 'TestDispatcher started with %d concurrent jobs' % concurrency) def _pool_init(self, address): global stop global m global ports stop = self._stop m = multiprocessing.managers.BaseManager(address) m.connect() ports = m.ports() def _dispatch_sync(self, test, cont): r = run_test(self.testdir, test, False) cont(r) return NonAsyncResult(r) def _dispatch_async(self, test, cont): return self._pool.apply_async(func=run_test, args=(self.testdir, test,), callback=cont) def dispatch(self, test): index = self._report.add_test(test) def cont(r): if not self._stop.is_set(): self._log.debug('freeing port') self._log.debug('adding result') self._report.add_result(index, r, r == RESULT_TIMEOUT) self._log.debug('finish continuation') fn = self._dispatch_async if self._async else self._dispatch_sync return fn(test, cont) def wait(self): if self._async: self._pool.close() self._pool.join() self._m.shutdown() return self._report.end() def terminate(self): self._stop.set() if self._async: self._pool.terminate() self._pool.join() self._m.shutdown()