當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。