示例#1
0
文件: tpool.py 项目: rdw/Eventlet
def setup():
    global _rfile, _wfile, _threads, _coro, _setup_already, _reqq, _rspq
    if _setup_already:
        return
    else:
        _setup_already = True
    try:
        _rpipe, _wpipe = os.pipe()
        _wfile = greenio.GreenPipe(_wpipe, "wb", 0)
        _rfile = greenio.GreenPipe(_rpipe, "rb", 0)
    except ImportError:
        # This is Windows compatibility -- use a socket instead of a pipe because
        # pipes don't really exist on Windows.
        import socket
        from eventlet import util

        sock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(("localhost", 0))
        sock.listen(50)
        csock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        csock.connect(("localhost", sock.getsockname()[1]))
        nsock, addr = sock.accept()
        _rfile = greenio.GreenSocket(csock).makefile("rb", 0)
        _wfile = nsock.makefile("wb", 0)

    _reqq = Queue(maxsize=-1)
    _rspq = Queue(maxsize=-1)
    for i in range(0, _nthreads):
        t = threading.Thread(target=tworker)
        t.setDaemon(True)
        t.start()
        _threads.add(t)

    _coro = greenthread.spawn_n(tpool_trampoline)
示例#2
0
def setup():
    global _rfile, _wfile, _threads, _coro, _setup_already, _reqq, _rspq
    if _setup_already:
        return
    else:
        _setup_already = True
    try:
        _rpipe, _wpipe = os.pipe()
        _wfile = greenio.GreenPipe(_wpipe, 'wb', 0)
        _rfile = greenio.GreenPipe(_rpipe, 'rb', 0)
    except ImportError:
        # This is Windows compatibility -- use a socket instead of a pipe because
        # pipes don't really exist on Windows.
        import socket
        from eventlet import util
        sock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(('localhost', 0))
        sock.listen(50)
        csock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        csock.connect(('localhost', sock.getsockname()[1]))
        nsock, addr = sock.accept()
        _rfile = greenio.GreenSocket(csock).makefile('rb', 0)
        _wfile = nsock.makefile('wb', 0)

    _reqq = Queue(maxsize=-1)
    _rspq = Queue(maxsize=-1)
    for i in range(0, _nthreads):
        t = threading.Thread(target=tworker)
        t.setDaemon(True)
        t.start()
        _threads.add(t)

    _coro = greenthread.spawn_n(tpool_trampoline)
示例#3
0
文件: host.py 项目: NxtCloud/nova
    def _init_events_pipe(self):
        """Create a self-pipe for the native thread to synchronize on.

        This code is taken from the eventlet tpool module, under terms
        of the Apache License v2.0.
        """

        self._event_queue = native_Queue.Queue()
        try:
            rpipe, wpipe = os.pipe()
            self._event_notify_send = greenio.GreenPipe(wpipe, 'wb', 0)
            self._event_notify_recv = greenio.GreenPipe(rpipe, 'rb', 0)
        except (ImportError, NotImplementedError):
            # This is Windows compatibility -- use a socket instead
            #  of a pipe because pipes don't really exist on Windows.
            sock = eventlet_util.__original_socket__(socket.AF_INET,
                                                     socket.SOCK_STREAM)
            sock.bind(('localhost', 0))
            sock.listen(50)
            csock = eventlet_util.__original_socket__(socket.AF_INET,
                                                      socket.SOCK_STREAM)
            csock.connect(('localhost', sock.getsockname()[1]))
            nsock, addr = sock.accept()
            self._event_notify_send = nsock.makefile('wb', 0)
            gsock = greenio.GreenSocket(csock)
            self._event_notify_recv = gsock.makefile('rb', 0)
示例#4
0
文件: host.py 项目: XiaoDongZhi/nova
    def _init_events_pipe(self):
        """Create a self-pipe for the native thread to synchronize on.

        This code is taken from the eventlet tpool module, under terms
        of the Apache License v2.0.
        """

        self._event_queue = native_Queue.Queue()
        try:
            rpipe, wpipe = os.pipe()
            self._event_notify_send = greenio.GreenPipe(wpipe, 'wb', 0)
            self._event_notify_recv = greenio.GreenPipe(rpipe, 'rb', 0)
        except (ImportError, NotImplementedError):
            # This is Windows compatibility -- use a socket instead
            #  of a pipe because pipes don't really exist on Windows.
            sock = eventlet_util.__original_socket__(socket.AF_INET,
                                                     socket.SOCK_STREAM)
            sock.bind(('localhost', 0))
            sock.listen(50)
            csock = eventlet_util.__original_socket__(socket.AF_INET,
                                                      socket.SOCK_STREAM)
            csock.connect(('localhost', sock.getsockname()[1]))
            nsock, addr = sock.accept()
            self._event_notify_send = nsock.makefile('wb', 0)
            gsock = greenio.GreenSocket(csock)
            self._event_notify_recv = gsock.makefile('rb', 0)
示例#5
0
文件: tpool.py 项目: Cue/eventlet
def setup():
    global _rfile, _wfile, _threads, _coro, _setup_already, _rspq, _reqq
    if _setup_already:
        return
    else:
        _setup_already = True
    try:
        _rpipe, _wpipe = os.pipe()
        _wfile = greenio.GreenPipe(_wpipe, "wb", 0)
        _rfile = greenio.GreenPipe(_rpipe, "rb", 0)
    except (ImportError, NotImplementedError):
        # This is Windows compatibility -- use a socket instead of a pipe because
        # pipes don't really exist on Windows.
        import socket
        from eventlet import util

        sock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(("localhost", 0))
        sock.listen(50)
        csock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        csock.connect(("localhost", sock.getsockname()[1]))
        nsock, addr = sock.accept()
        _rfile = greenio.GreenSocket(csock).makefile("rb", 0)
        _wfile = nsock.makefile("wb", 0)

    _rspq = Queue(maxsize=-1)
    _reqq = Queue(maxsize=-1)
    assert _nthreads >= 0, "Can't specify negative number of threads"
    if _nthreads == 0:
        import warnings

        warnings.warn(
            "Zero threads in tpool.  All tpool.execute calls will\
            execute in main thread.  Check the value of the environment \
            variable EVENTLET_THREADPOOL_SIZE.",
            RuntimeWarning,
        )
    for i in xrange(_nthreads):
        t = threading.Thread(target=tworker, name="tpool_thread_%s" % i, args=(_reqq,))
        t.setDaemon(True)
        t.start()
        _threads.append(t)

    _coro = greenthread.spawn_n(tpool_trampoline)
示例#6
0
文件: tpool.py 项目: MarSoft/eventlet
def setup():
    global _rfile, _wfile, _threads, _coro, _setup_already, _rspq, _reqq
    if _setup_already:
        return
    else:
        _setup_already = True
    try:
        _rpipe, _wpipe = os.pipe()
        _wfile = greenio.GreenPipe(_wpipe, 'wb', 0)
        _rfile = greenio.GreenPipe(_rpipe, 'rb', 0)
    except (ImportError, NotImplementedError):
        # This is Windows compatibility -- use a socket instead of a pipe because
        # pipes don't really exist on Windows.
        import socket
        from eventlet import util
        sock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind(('localhost', 0))
        sock.listen(50)
        csock = util.__original_socket__(socket.AF_INET, socket.SOCK_STREAM)
        csock.connect(('localhost', sock.getsockname()[1]))
        nsock, addr = sock.accept()
        _rfile = greenio.GreenSocket(csock).makefile('rb', 0)
        _wfile = nsock.makefile('wb',0)

    _rspq = Queue(maxsize=-1)
    _reqq = Queue(maxsize=-1)
    assert _nthreads >= 0, "Can't specify negative number of threads"
    if _nthreads == 0:
        import warnings
        warnings.warn("Zero threads in tpool.  All tpool.execute calls will\
            execute in main thread.  Check the value of the environment \
            variable EVENTLET_THREADPOOL_SIZE.", RuntimeWarning)
    for i in xrange(_nthreads):
        t = threading.Thread(target=tworker, 
                             name="tpool_thread_%s" % i, 
                             args=(_reqq,))
        t.setDaemon(True)
        t.start()
        _threads.append(t)
        

    _coro = greenthread.spawn_n(tpool_trampoline)