Ejemplo n.º 1
0
    def wrapper(*args, **kwargs):
        future = Future()

        launch_thread(name, _function_handler, daemon, function, args, kwargs,
                      future)

        return future
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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])
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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)), [])
Ejemplo n.º 15
0
 def _start_pool(self):
     self._pool_manager.start()
     self._loops = (launch_thread(pool_manager_loop, self._pool_manager), )
     self._context.state = RUNNING
Ejemplo n.º 16
0
 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])
Ejemplo n.º 17
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)), [])
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
    def create_workers(self):
        for _ in range(self.context.workers - len(self.workers)):
            worker = launch_thread(worker_thread, self.context)

            self.workers.append(worker)
Ejemplo n.º 20
0
 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])
Ejemplo n.º 21
0
 def _start_pool(self):
     self._pool_manager.start()
     self._loops = (launch_thread(pool_manager_loop, self._pool_manager),)
     self._context.state = RUNNING
Ejemplo n.º 22
0
    def wrapper(*args, **kwargs):
        future = Future()

        launch_thread(_function_handler, function, args, kwargs, future)

        return future
Ejemplo n.º 23
0
 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
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
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)), [])
Ejemplo n.º 26
0
 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)
Ejemplo n.º 27
0
 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
Ejemplo n.º 28
0
 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)
Ejemplo n.º 29
0
    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)
Ejemplo n.º 30
0
    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
Ejemplo n.º 31
0
 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)), [])
Ejemplo n.º 32
0
 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)
Ejemplo n.º 33
0
 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])