def wrapper(*args, **kwargs): future = Future() launch_thread(name, _function_handler, daemon, function, args, kwargs, future) return future
def _start_pool(self): with self._context.state_mutex: if self._context.state == CREATED: self._pool_manager.start() self._loops = (launch_thread(None, task_scheduler_loop, self._pool_manager), launch_thread(None, pool_manager_loop, self._pool_manager), launch_thread(None, message_manager_loop, self._pool_manager)) self._context.state = RUNNING
def test_waitforthreads_multiple(self): """Waitforthreads waits for multiple threads.""" threads = [] for _ in range(5): threads.append(launch_thread(thread_function, 0.01)) time.sleep(0.1) self.assertEqual(list(waitforthreads(threads)), threads)
def _start_pool(self): with self._context.state_mutex: if self._context.state == CREATED: self._pool_manager.start() self._loops = (launch_thread(None, pool_manager_loop, True, self._pool_manager),) self._context.state = RUNNING
def _start_pool(self): with self._context.state_mutex: if self._context.state == CREATED: self._pool_manager.start() self._loops = (launch_thread(pool_manager_loop, self._pool_manager),) self._context.state = RUNNING
def wrapper(*args, **kwargs): future = ProcessFuture() reader, writer = Pipe(duplex=False) if get_start_method() != 'fork': target = _trampoline args = [function.__name__, function.__module__] + list(args) else: target = function worker = launch_process(_function_handler, target, args, kwargs, writer) writer.close() future.set_running_or_notify_cancel() launch_thread(_worker_handler, future, worker, reader, timeout) return future
def wrapper(*args, **kwargs): future = ProcessFuture() reader, writer = Pipe(duplex=False) if get_start_method() != 'fork': target = _trampoline args = [function.__name__, function.__module__] + list(args) else: target = function worker = launch_process( _function_handler, target, args, kwargs, writer) writer.close() future.set_running_or_notify_cancel() launch_thread(_worker_handler, future, worker, reader, timeout) return future
def wrapper(*args, **kwargs): future = ProcessFuture() reader, writer = mp_context.Pipe(duplex=False) if start_method != 'fork': target = _trampoline args = [_qualname(function), function.__module__] + list(args) else: target = function worker = launch_process(name, _function_handler, daemon, mp_context, target, args, kwargs, (reader, writer)) writer.close() future.set_running_or_notify_cancel() launch_thread(name, _worker_handler, True, future, worker, reader, timeout) return future
def test_waitforthreads_restore(self): """Waitforthreads get_ident is restored to original one.""" if hasattr(threading, 'get_ident'): expected = threading.get_ident else: expected = threading._get_ident thread = launch_thread(thread_function, 0) time.sleep(0.01) waitforthreads([thread]) if hasattr(threading, 'get_ident'): self.assertEqual(threading.get_ident, expected) else: self.assertEqual(threading._get_ident, expected)
def test_waitforthreads_spurious(self): """Waitforthreads tolerates spurious wakeups.""" lock = threading.RLock() thread = launch_thread(spurious_wakeup_function, 0.1, lock) self.assertEqual(list(waitforthreads([thread])), [thread])
def test_waitforthreads_single(self): """Waitforthreads waits for a single thread.""" thread = launch_thread(thread_function, 0.01) self.assertEqual(list(waitforthreads([thread]))[0], thread)
def test_waitforthreads_timeout(self): """Waitforthreads returns empty list if timeout.""" thread = launch_thread(thread_function, 0.1) self.assertEqual(list(waitforthreads([thread], timeout=0.01)), [])
def _start_pool(self): self._pool_manager.start() self._loops = (launch_thread(pool_manager_loop, self._pool_manager), ) self._context.state = RUNNING
def test_waitforqueues_single(self): """Waitforqueues waits for a single queue.""" launch_thread(queue_function, self.queues, 0, 0.01) self.assertEqual(list(waitforqueues(self.queues))[0], self.queues[0])
def test_waitforqueues_timeout(self): """Waitforqueues returns empty list if timeout.""" launch_thread(queue_function, self.queues, 0, 0.1) self.assertEqual(list(waitforqueues(self.queues, timeout=0.01)), [])
def test_waitforqueues_multiple(self): """Waitforqueues waits for multiple queues.""" for index in range(3): launch_thread(queue_function, self.queues, index, 0.01) time.sleep(0.1) self.assertEqual(list(waitforqueues(self.queues)), self.queues)
def create_workers(self): for _ in range(self.context.workers - len(self.workers)): worker = launch_thread(worker_thread, self.context) self.workers.append(worker)
def _start_pool(self): self._pool_manager.start() self._loops = (launch_thread(pool_manager_loop, self._pool_manager),) self._context.state = RUNNING
def wrapper(*args, **kwargs): future = Future() launch_thread(_function_handler, function, args, kwargs, future) return future
def _start_pool(self): self._pool_manager.start() self._loops = (launch_thread(task_scheduler_loop, self._pool_manager), launch_thread(pool_manager_loop, self._pool_manager), launch_thread(message_manager_loop, self._pool_manager)) self._context.state = RUNNING
def test_waitforqueues_restore(self): """Waitforqueues Queue object is restored to original one.""" expected = sorted(dir(self.queues[0])) launch_thread(queue_function, self.queues, 0, 0) waitforqueues(self.queues) self.assertEqual(sorted(dir(self.queues[0])), expected)
def create_workers(self): for _ in range(self.context.workers - len(self.workers)): worker = launch_thread(None, worker_thread, True, self.context) self.workers.append(worker)
def create_workers(self): for _ in range(self.context.workers - len(self.workers)): worker = launch_thread(None, worker_thread, self.context) self.workers[worker.ident] = worker