当前位置: 首页>>代码示例>>Python>>正文


Python greenio.GreenPipe方法代码示例

本文整理汇总了Python中eventlet.greenio.GreenPipe方法的典型用法代码示例。如果您正苦于以下问题:Python greenio.GreenPipe方法的具体用法?Python greenio.GreenPipe怎么用?Python greenio.GreenPipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eventlet.greenio的用法示例。


在下文中一共展示了greenio.GreenPipe方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def __init__(self, args, bufsize=0, *argss, **kwds):
            self.args = args
            # Forward the call to base-class constructor
            subprocess_orig.Popen.__init__(self, args, 0, *argss, **kwds)
            # Now wrap the pipes, if any. This logic is loosely borrowed from
            # eventlet.processes.Process.run() method.
            for attr in "stdin", "stdout", "stderr":
                pipe = getattr(self, attr)
                if pipe is not None and type(pipe) != greenio.GreenPipe:
                    # https://github.com/eventlet/eventlet/issues/243
                    # AttributeError: '_io.TextIOWrapper' object has no attribute 'mode'
                    mode = getattr(pipe, 'mode', '')
                    if not mode:
                        if pipe.readable():
                            mode += 'r'
                        if pipe.writable():
                            mode += 'w'
                        # ValueError: can't have unbuffered text I/O
                        if bufsize == 0:
                            bufsize = -1
                    wrapped_pipe = greenio.GreenPipe(pipe, mode, bufsize)
                    setattr(self, attr, wrapped_pipe) 
开发者ID:htwenning,项目名称:remoteControlPPT,代码行数:24,代码来源:subprocess.py

示例2: test_pipe

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe(self):
        r, w = os.pipe()
        rf = greenio.GreenPipe(r, 'rb')
        wf = greenio.GreenPipe(w, 'wb', 0)

        def sender(f, content):
            for ch in map(six.int2byte, six.iterbytes(content)):
                eventlet.sleep(0.0001)
                f.write(ch)
            f.close()

        one_line = b"12345\n"
        eventlet.spawn(sender, wf, one_line * 5)
        for i in range(5):
            line = rf.readline()
            eventlet.sleep(0.01)
            self.assertEqual(line, one_line)
        self.assertEqual(rf.readline(), b'') 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:20,代码来源:greenio_test.py

示例3: test_pipe_writes_large_messages

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe_writes_large_messages(self):
        r, w = os.pipe()

        r = greenio.GreenPipe(r, 'rb')
        w = greenio.GreenPipe(w, 'wb')

        large_message = b"".join([1024 * six.int2byte(i) for i in range(65)])

        def writer():
            w.write(large_message)
            w.close()

        gt = eventlet.spawn(writer)

        for i in range(65):
            buf = r.read(1024)
            expected = 1024 * six.int2byte(i)
            self.assertEqual(
                buf, expected,
                "expected=%r..%r, found=%r..%r iter=%d"
                % (expected[:4], expected[-4:], buf[:4], buf[-4:], i))
        gt.wait() 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:24,代码来源:greenio_test.py

示例4: test_pipe_writes_large_messages

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe_writes_large_messages():
    r, w = os.pipe()

    r = greenio.GreenPipe(r)
    w = greenio.GreenPipe(w, 'w')

    large_message = b"".join([1024 * chr(i) for i in range(65)])

    def writer():
        w.write(large_message)
        w.close()

    gt = eventlet.spawn(writer)

    for i in range(65):
        buf = r.read(1024)
        expected = 1024 * chr(i)
        if buf != expected:
            print(
                "expected=%r..%r, found=%r..%r iter=%d"
                % (expected[:4], expected[-4:], buf[:4], buf[-4:], i))
    gt.wait() 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:24,代码来源:greenio_memtest.py

示例5: _init_events_pipe

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
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 = native_socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind(('localhost', 0))
            sock.listen(50)
            csock = native_socket.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) 
开发者ID:BU-NU-CLOUD-SP16,项目名称:Trusted-Platform-Module-nova,代码行数:26,代码来源:host.py

示例6: create_pipe

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def create_pipe():
    rpipe, wpipe = os.pipe()
    rfile = greenio.GreenPipe(rpipe, 'rb', 0)
    wfile = greenio.GreenPipe(wpipe, 'wb', 0)
    return rfile, wfile 
开发者ID:openstack,项目名称:os-xenapi,代码行数:7,代码来源:utils.py

示例7: fdopen

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def fdopen(fd, *args, **kw):
    """fdopen(fd [, mode='r' [, bufsize]]) -> file_object

    Return an open file object connected to a file descriptor."""
    if not isinstance(fd, int):
        raise TypeError('fd should be int, not %r' % fd)
    try:
        return greenio.GreenPipe(fd, *args, **kw)
    except IOError as e:
        raise OSError(*e.args) 
开发者ID:htwenning,项目名称:remoteControlPPT,代码行数:12,代码来源:os.py

示例8: test_pipe_read

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe_read(self):
        # ensure that 'readline' works properly on GreenPipes when data is not
        # immediately available (fd is nonblocking, was raising EAGAIN)
        # also ensures that readline() terminates on '\n' and '\r\n'
        r, w = os.pipe()

        r = greenio.GreenPipe(r, 'rb')
        w = greenio.GreenPipe(w, 'wb')

        def writer():
            eventlet.sleep(.1)

            w.write(b'line\n')
            w.flush()

            w.write(b'line\r\n')
            w.flush()

        gt = eventlet.spawn(writer)

        eventlet.sleep(0)

        line = r.readline()
        self.assertEqual(line, b'line\n')

        line = r.readline()
        self.assertEqual(line, b'line\r\n')

        gt.wait() 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:31,代码来源:greenio_test.py

示例9: test_pip_read_until_end

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pip_read_until_end(self):
        # similar to test_pip_read above but reading until eof
        r, w = os.pipe()

        r = greenio.GreenPipe(r, 'rb')
        w = greenio.GreenPipe(w, 'wb')

        w.write(b'c' * DEFAULT_BUFFER_SIZE * 2)
        w.close()

        buf = r.read()  # no chunk size specified; read until end
        self.assertEqual(len(buf), 2 * DEFAULT_BUFFER_SIZE)
        self.assertEqual(buf[:3], b'ccc') 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:15,代码来源:greenio_test.py

示例10: test_pipe_read_unbuffered

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe_read_unbuffered(self):
        # Ensure that seting the buffer size works properly on GreenPipes,
        # it used to be ignored on Python 2 and the test would hang on r.readline()
        # below.
        r, w = os.pipe()

        r = greenio.GreenPipe(r, 'rb', 0)
        w = greenio.GreenPipe(w, 'wb', 0)

        w.write(b'line\n')

        line = r.readline()
        self.assertEqual(line, b'line\n')
        r.close()
        w.close() 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:17,代码来源:greenio_test.py

示例11: test_truncate

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_truncate(self):
        f = greenio.GreenPipe(self.tempdir + "/TestFile", 'wb+', 1024)
        f.write(b'1234567890')
        f.truncate(9)
        self.assertEqual(f.tell(), 9) 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:7,代码来源:greenio_test.py

示例12: test_pipe_context

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def test_pipe_context():
    # ensure using a pipe as a context actually closes it.
    r, w = os.pipe()
    r = greenio.GreenPipe(r)
    w = greenio.GreenPipe(w, 'w')

    with r:
        pass
    assert r.closed and not w.closed

    with w as f:
        assert f == w
    assert r.closed and w.closed 
开发者ID:openstack,项目名称:deb-python-eventlet,代码行数:15,代码来源:greenio_test.py

示例13: _create_pipe

# 需要导入模块: from eventlet import greenio [as 别名]
# 或者: from eventlet.greenio import GreenPipe [as 别名]
def _create_pipe(self):
        rpipe, wpipe = os.pipe()
        rfile = greenio.GreenPipe(rpipe, 'rb', 0)
        wfile = greenio.GreenPipe(wpipe, 'wb', 0)
        return rfile, wfile 
开发者ID:BU-NU-CLOUD-SP16,项目名称:Trusted-Platform-Module-nova,代码行数:7,代码来源:vdi_through_dev.py


注:本文中的eventlet.greenio.GreenPipe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。