def test_worker_attributes(name, multiprocessing, pool): """Test the attributes""" try: with pr.get_worker(name=name, multiprocessing=multiprocessing) as worker: assert worker.multiprocessing == multiprocessing assert isinstance(worker.pool, pool) finally: pr.remove_worker(name=name)
def test_processes(execute, name, multiprocessing, result_class): "Run the processes" try: execute( pr.get_worker(name=name, multiprocessing=multiprocessing, result_class=result_class)) finally: pr.remove_worker(name=name)
def test_with(execute, name, multiprocessing, result_class): """with statement""" try: with pr.get_worker(name=name, multiprocessing=multiprocessing, result_class=result_class) as worker: execute(worker) finally: pr.remove_worker(name=name)
def test_wait(name, multiprocessing, timeout): """Wait for a while""" try: with pr.get_worker(name=name, multiprocessing=multiprocessing) as worker: for i in range(10): worker(sleep, i) worker.wait(timeout) results = [j.get(0) for j in worker.jobs] assert len(results) == 10 finally: pr.remove_worker(name=name)
def test_log_multiprocessing_initmain(qhandler, logger, logger_level, list_handler, use_process, n_logs): """Log from multiple processes to subprocess, handler initialised in main """ logger.addHandler(qhandler[1]) worker = phproc.get_worker(name=logger.name, multiprocessing=True) with phlog.SetupQueueListener(qhandler[0], handlers=[list_handler[0], ], use_process=use_process): for i in range(n_logs): worker(_log_one_logname, logger.name, logger_level+1) worker.get_results() worker.close() assert len(list_handler[1]) == n_logs for record in list_handler[1]: assert record.levelno > logger_level