Пример #1
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    if not raise_error:
        wait(greenlets, timeout=timeout, count=count)
    else:
        for obj in iwait(greenlets, timeout=timeout, count=count):
            if getattr(obj, 'exception', None) is not None:
                if hasattr(obj, '_raise_exception'):
                    obj._raise_exception()
                else:
                    raise obj.exception
Пример #2
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    if not raise_error:
        wait(greenlets, timeout=timeout)
    else:
        for obj in iwait(greenlets, timeout=timeout):
            if getattr(obj, 'exception', None) is not None:
                raise obj.exception
            if count is not None:
                count -= 1
                if count <= 0:
                    break
Пример #3
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    if not raise_error:
        wait(greenlets, timeout=timeout)
    else:
        for obj in iwait(greenlets, timeout=timeout):
            if getattr(obj, 'exception', None) is not None:
                raise obj.exception
            if count is not None:
                count -= 1
                if count <= 0:
                    break
Пример #4
0
def bench_wait_func_ready():
    from gevent.hub import wait
    class ToWatch(object):
        def rawlink(self, cb):
            cb(self)

    watched_objects = [ToWatch() for _ in range(N)]

    t0 = perf_counter()

    wait(watched_objects)

    return perf_counter() - t0
Пример #5
0
def _manager_process(addr):
    logger = get_logger()
    spawn(idle_watcher)
    try:
        listener: Listener = Listener(addr, "AF_UNIX")

        with listener:
            manager = SyncManager()
            manager.start(manager_init)
            try:

                def process_queue(q: Queue, idx: int):
                    for val_idx in range(0, QUEUE_DEPTH):
                        put_string = f"Request #{idx}, Value #{val_idx}"
                        logger.info(f"**** Sending {put_string} on {q._id}")
                        q.put(put_string)
                        logger.info(f"**** Sent {put_string} on {q._id}")
                        sleep(0.05)

                    logger.info(
                        f"**** Putting None in queue request #{idx} to empty on {q._id}"
                    )
                    q.put(None)
                    logger.info(
                        f"**** Waiting for queue request #{idx} to empty on {q._id}"
                    )
                    q.join()
                    logger.info(
                        f"**** All done with request #{idx} on {q._id}")

                def process_conn(conn: Connection, idx: int):
                    with conn:
                        logger.info(f"**** Accepted request #{idx}")
                        q: Queue = manager.Queue(QUEUE_SIZE)
                        logger.info(
                            f"**** Passing request #{idx} queue {q._id}")
                        conn.send(q)
                        logger.info(
                            f"**** Passed request #{idx} queue {q._id}")

                    spawn(process_queue, q, idx)

                for i in range(0, REQUEST_COUNT):
                    spawn(process_conn, listener.accept(), i)

                wait(timeout=300)
                # logger.warning("\n".join(format_run_info()))
            finally:
                manager.shutdown()
    finally:
        get_hub().destroy()
Пример #6
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    if not raise_error:
        wait(greenlets, timeout=timeout)
        for green in greenlets:
            if hasattr(green, "_exc_info"):
                del green._exc_info
    else:
        for obj in iwait(greenlets, timeout=timeout):
            if getattr(obj, 'exception', None) is not None:
                obj.raise_exception()
            if count is not None:
                count -= 1
                if count <= 0:
                    break
Пример #7
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    if not raise_error:
        wait(greenlets, timeout=timeout)
        for green in greenlets:
            if hasattr(green, "_exc_info"):
                del green._exc_info
    else:
        for obj in iwait(greenlets, timeout=timeout):
            if getattr(obj, 'exception', None) is not None:
                obj.raise_exception()
            if count is not None:
                count -= 1
                if count <= 0:
                    break
Пример #8
0
    def _test_manager(self, ctx, remote_trace):
        p = ctx.Process(target=manager_process, args=(self.addr, remote_trace))
        p.start()

        sleep(3)

        results = []
        for i in range(0, REQUEST_COUNT):
            spawn(self.manager_client, results)

        spawn(idle_watcher)

        p.join(300)
        wait(timeout=5)

        self.assertFalse(p.is_alive())
        self.assertEqual(p.exitcode, 0)

        for result in results:
            self.assertIsInstance(result, str)
            self.assertRegex(result, r"Request #\d+, Value #\d+")

        self.assertEqual(len(results), QUEUE_DEPTH * REQUEST_COUNT)
Пример #9
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    """
    Wait for the ``greenlets`` to finish.

    :param greenlets: A sequence (supporting :func:`len`) of greenlets to wait for.
    :keyword float timeout: If given, the maximum number of seconds to wait.
    :return: A sequence of the greenlets that finished before the timeout (if any)
        expired.
    """
    if not raise_error:
        return wait(greenlets, timeout=timeout, count=count)

    done = []
    for obj in iwait(greenlets, timeout=timeout, count=count):
        if getattr(obj, 'exception', None) is not None:
            if hasattr(obj, '_raise_exception'):
                obj._raise_exception()
            else:
                raise obj.exception
        done.append(obj)
    return done
Пример #10
0
def joinall(greenlets, timeout=None, raise_error=False, count=None):
    """
    Wait for the ``greenlets`` to finish.

    :param greenlets: A sequence (supporting :func:`len`) of greenlets to wait for.
    :keyword float timeout: If given, the maximum number of seconds to wait.
    :return: A sequence of the greenlets that finished before the timeout (if any)
        expired.
    """
    if not raise_error:
        return wait(greenlets, timeout=timeout, count=count)

    done = []
    for obj in iwait(greenlets, timeout=timeout, count=count):
        if getattr(obj, 'exception', None) is not None:
            if hasattr(obj, '_raise_exception'):
                obj._raise_exception()
            else:
                raise obj.exception
        done.append(obj)
    return done
def gevent_waiter(fd, hub=gevent.hub.get_hub()):
    hub.wait(hub.loop.io(fd, 1))
Пример #12
0
def gevent_waiter(fd, hub=gevent.hub.get_hub()):
    hub.wait(hub.loop.io(fd, 1))