コード例 #1
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
コード例 #2
0
ファイル: process.py プロジェクト: noxdafox/pebble
    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
コード例 #3
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
コード例 #4
0
ファイル: process.py プロジェクト: ehudhala/pebble
    def schedule(self, function, args=(), kwargs={}, timeout=None):
        """Schedules *function* to be run the Pool.

        *args* and *kwargs* will be forwareded to the scheduled function
        respectively as arguments and keyword arguments.

        *timeout* is an integer, if expires the task will be terminated
        and *Future.result()* will raise *TimeoutError*.

        A *pebble.ProcessFuture* object is returned.

        """
        self._check_pool_state()

        future = ProcessFuture()
        payload = TaskPayload(function, args, kwargs)
        task = Task(next(self._task_counter), future, timeout, payload)

        self._context.task_queue.put(task)

        return future