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


Python os.pipe方法代码示例

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


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

示例1: _pipe2_by_pipe

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def _pipe2_by_pipe(flags):
    """A ``pipe2`` implementation using :func:`os.pipe`.

    ``flags`` is an integer providing the flags to ``pipe2``.

    .. warning::

       This implementation is not atomic!

    Return a pair of file descriptors ``(r, w)``.

    """
    fds = os.pipe()
    if flags & os.O_NONBLOCK != 0:
        for fd in fds:
            set_fd_status_flag(fd, os.O_NONBLOCK)
    if flags & O_CLOEXEC != 0:
        for fd in fds:
            set_fd_flag(fd, O_CLOEXEC)
    return fds 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:pipe.py

示例2: write_payload

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def write_payload(self):
        port = self._port
        tar_path = self.create_payload_tar()

        log.debug(port.read_until("/ # "))
        port.write("base64 -d | tar zxf -\n")
        port.flush()
        #(tarr, tarw) = os.pipe()
        #tar = tarfile.open(mode='w|gz', fileobj=tarw)
        #tar.add("payload/patch_toon.sh")

        log.info("Transferring payload")
        with open(tar_path, 'r') as f:
            base64.encode(f, port)

        os.remove(tar_path)

        port.flush()
        port.reset_input_buffer()
        port.write("\x04")
        port.flush() 
开发者ID:martenjacobs,项目名称:ToonRooter,代码行数:23,代码来源:rooter.py

示例3: _init_with_header

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def _init_with_header(self, header_lines):
    # Following pipe is responsible for supplying lines from child process to
    # the parent process, which will be fed into PySam object through an actual
    # file descriptor.
    return_pipe_read, return_pipe_write = os.pipe()
    # Since child process doesn't have access to the lines that need to be
    # parsed, following pipe is needed to supply them from _get_variant() method
    # into the child process, to be propagated back into the return pipe.
    send_pipe_read, send_pipe_write = os.pipe()
    pid = os.fork()
    if pid:
      self._process_pid = pid
      self._init_parent_process(return_pipe_read, send_pipe_write)
    else:
      self._init_child_process(send_pipe_read,
                               return_pipe_write,
                               header_lines,
                               self._pre_infer_headers) 
开发者ID:googlegenomics,项目名称:gcp-variant-transforms,代码行数:20,代码来源:vcf_parser.py

示例4: read_from_fd

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def read_from_fd(self):
        try:
            chunk = os.read(self.fd, self.read_chunk_size)
        except (IOError, OSError) as e:
            if errno_from_exception(e) in _ERRNO_WOULDBLOCK:
                return None
            elif errno_from_exception(e) == errno.EBADF:
                # If the writing half of a pipe is closed, select will
                # report it as readable but reads will fail with EBADF.
                self.close(exc_info=True)
                return None
            else:
                raise
        if not chunk:
            self.close()
            return None
        return chunk 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:iostream.py

示例5: test_pipe_iostream

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

        rs = PipeIOStream(r, io_loop=self.io_loop)
        ws = PipeIOStream(w, io_loop=self.io_loop)

        ws.write(b"hel")
        ws.write(b"lo world")

        rs.read_until(b' ', callback=self.stop)
        data = self.wait()
        self.assertEqual(data, b"hello ")

        rs.read_bytes(3, self.stop)
        data = self.wait()
        self.assertEqual(data, b"wor")

        ws.close()

        rs.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b"ld")

        rs.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:iostream_test.py

示例6: test_pipe_iostream_big_write

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

        rs = PipeIOStream(r, io_loop=self.io_loop)
        ws = PipeIOStream(w, io_loop=self.io_loop)

        NUM_BYTES = 1048576

        # Write 1MB of data, which should fill the buffer
        ws.write(b"1" * NUM_BYTES)

        rs.read_bytes(NUM_BYTES, self.stop)
        data = self.wait()
        self.assertEqual(data, b"1" * NUM_BYTES)

        ws.close()
        rs.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:iostream_test.py

示例7: _newpipe

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def _newpipe(encoder, decoder):
    """Create new pipe via `os.pipe()` and return `(_GIPCReader, _GIPCWriter)`
    tuple.

    os.pipe() implementation on Windows (https://goo.gl/CiIWvo):
       - CreatePipe(&read, &write, NULL, 0)
       - anonymous pipe, system handles buffer size
       - anonymous pipes are implemented using named pipes with unique names
       - asynchronous (overlapped) read and write operations not supported
    os.pipe() implementation on Unix (http://linux.die.net/man/7/pipe):
       - based on pipe()
       - common Linux: pipe buffer is 4096 bytes, pipe capacity is 65536 bytes
    """
    r, w = os.pipe()
    return (_GIPCReader(r, decoder), _GIPCWriter(w, encoder))


# Define default encoder and decoder functions for pipe data serialization. 
开发者ID:jgehrcke,项目名称:gipc,代码行数:20,代码来源:gipc.py

示例8: _write

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def _write(self, bindata):
        """Write `bindata` to pipe in a gevent-cooperative manner.

        POSIX-compliant system notes (http://linux.die.net/man/7/pipe:):
            - Since Linux 2.6.11, the pipe capacity is 65536 bytes
            - Relevant for large messages (O_NONBLOCK enabled,
              n > PIPE_BUF (4096 Byte, usually)):
                "If the pipe is full, then write(2) fails, with errno set
                to EAGAIN. Otherwise, from 1 to n bytes may be written (i.e.,
                a "partial write" may occur; the caller should check the
                return value from write(2) to see how many bytes were
                actually written), and these bytes may be interleaved with
                writes by other processes."

            EAGAIN is handled within _write_nonblocking; partial writes here.
        """
        bindata = memoryview(bindata)
        while True:
            # Causes OSError when read end is closed (broken pipe).
            bytes_written = _write_nonblocking(self._fd, bindata)
            if bytes_written == len(bindata):
                break
            bindata = bindata[bytes_written:] 
开发者ID:jgehrcke,项目名称:gipc,代码行数:25,代码来源:gipc.py

示例9: put

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def put(self, o):
        """Encode object ``o`` and write it to the pipe.
        Block gevent-cooperatively until all data is written. The default
        encoder is ``pickle.dumps``.

        :arg o: a Python object that is encodable with the encoder of choice.

        Raises:
            - :exc:`GIPCError`
            - :exc:`GIPCClosed`
            - :exc:`pickle.PicklingError`

        """
        self._validate()
        with self._lock:
            bindata = self._encoder(o)
            self._write(struct.pack("!i", len(bindata)) + bindata) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:19,代码来源:gipc.py

示例10: init_signals

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def init_signals(self):
        """\
        Initialize master signal handling. Most of the signals
        are queued. Child signals only wake up the master.
        """
        # close old PIPE
        if self.PIPE:
            [os.close(p) for p in self.PIPE]

        # initialize the pipe
        self.PIPE = pair = os.pipe()
        for p in pair:
            util.set_non_blocking(p)
            util.close_on_exec(p)

        self.log.close_on_exec()

        # initialize all signals
        [signal.signal(s, self.signal) for s in self.SIGNALS]
        signal.signal(signal.SIGCHLD, self.handle_chld) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:arbiter.py

示例11: shell

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def shell(cmd):
    """Run each line of a shell script; raise an exception if any line returns
    a nonzero value.
    """
    pin, pout = os.pipe()
    proc = sp.Popen('/bin/bash', stdin=sp.PIPE)
    for line in cmd.split('\n'):
        line = line.strip()
        if line.startswith('#'):
            print('\033[33m> ' + line + '\033[0m')
        else:
            print('\033[32m> ' + line + '\033[0m')
        if line.startswith('cd '):
            os.chdir(line[3:])
        proc.stdin.write((line + '\n').encode('utf-8'))
        proc.stdin.write(('echo $? 1>&%d\n' % pout).encode('utf-8'))
        ret = ""
        while not ret.endswith('\n'):
            ret += os.read(pin, 1)
        ret = int(ret.strip())
        if ret != 0:
            print("\033[31mLast command returned %d; bailing out.\033[0m" % ret)
            sys.exit(-1)
    proc.stdin.close()
    proc.wait() 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:27,代码来源:shell.py

示例12: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def __init__(self, cmd, bufsize=-1):
        _cleanup()
        self.cmd = cmd
        p2cread, p2cwrite = os.pipe()
        c2pread, c2pwrite = os.pipe()
        self.pid = os.fork()
        if self.pid == 0:
            # Child
            os.dup2(p2cread, 0)
            os.dup2(c2pwrite, 1)
            os.dup2(c2pwrite, 2)
            self._run_child(cmd)
        os.close(p2cread)
        self.tochild = os.fdopen(p2cwrite, 'w', bufsize)
        os.close(c2pwrite)
        self.fromchild = os.fdopen(c2pread, 'r', bufsize) 
开发者ID:glmcdona,项目名称:meddle,代码行数:18,代码来源:popen2.py

示例13: run

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def run(engine_factory, source_name, input_queue_maxsize, port, num_tokens,
        message_max_size=None):
    engine_read, server_write = multiprocessing.Pipe(duplex=False)

    # We cannot read from multiprocessing.Pipe without blocking the event
    # loop
    server_read, engine_write = os.pipe()

    local_server = _LocalServer(
        num_tokens, input_queue_maxsize, server_write, server_read)
    local_server.add_source_consumed(source_name)

    engine_process = multiprocessing.Process(
        target=_run_engine,
        args=(engine_factory, engine_read, server_read, engine_write))
    try:
        engine_process.start()
        os.close(engine_write)
        local_server.launch(port, message_max_size)
    finally:
        local_server.cleanup()
        os.close(server_read)

    raise Exception('Server stopped') 
开发者ID:cmusatyalab,项目名称:gabriel,代码行数:26,代码来源:local_engine.py

示例14: send

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def send(self, request):
		"""
		Encode and send a request through the pipe to the opposite end. This
		also sets the 'sequence' member of the request and increments the stored
		value.

		:param dict request: A request.
		"""
		request['sequence'] = self.sequence_number
		self.sequence_number += 1
		if self.sequence_number > 0xffffffff:
			self.sequence_number = 0
		self._raw_send(request)
		log_msg = "sent request with sequence number {0}".format(request['sequence'])
		if 'action' in request:
			log_msg += " and action '{0}'".format(request['action'])
		self.logger.debug(log_msg) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:19,代码来源:aaa.py

示例15: test_it

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe [as 别名]
def test_it(self):
        getline = os.path.join(here, 'fixtureapps', 'getline.py')
        cmds = (
            [self.exe, getline, 'http://%s:%d/sleepy' % self.bound_to],
            [self.exe, getline, 'http://%s:%d/' % self.bound_to]
        )
        r, w = os.pipe()
        procs = []
        for cmd in cmds:
            procs.append(subprocess.Popen(cmd, stdout=w))
        time.sleep(3)
        for proc in procs:
            if proc.returncode is not None: # pragma: no cover
                proc.terminate()
        # the notsleepy response should always be first returned (it sleeps
        # for 2 seconds, then returns; the notsleepy response should be
        # processed in the meantime)
        result = os.read(r, 10000)
        os.close(r)
        os.close(w)
        self.assertEqual(result, b'notsleepy returnedsleepy returned') 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:23,代码来源:test_functional.py


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