Python3 os.pipe() 方法
Python 3 教程
· 2019-02-07 17:13:16
概述
os.pipe() 方法用于创建一个管道, 返回一对文件描述符(r, w) 分别为读和写。
语法
pipe()方法语法格式如下:
os.pipe()
参数
无
返回值
返回文件描述符对。
实例
以下实例演示了 pipe() 方法的使用:
#!/usr/bin/python3
import os, sys
print ("The child will write text to a pipe and ")
print ("the parent will read the text written by child...")
# 文件描述符 r, w 用于读、写
r, w = os.pipe()
processid = os.fork()
if processid:
# 父进程
# 关闭文件描述符 w
os.close(w)
r = os.fdopen(r)
print ("Parent reading")
str = r.read()
print ("text =", str)
sys.exit(0)
else:
# 子进程
os.close(r)
w = os.fdopen(w, 'w')
print ("Child writing")
w.write("Text written by child...")
w.close()
print ("Child closing")
sys.exit(0)
执行以上程序输出结果为:
The child will write text to a pipe and the parent will read the text written by child... Parent reading Child writing Child closing text = Text written by child...
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
区块链技术驱动金融
阿尔文德·纳拉亚南、约什·贝努、爱德华·费尔顿、安德鲁·米勒、史蒂文·戈德费德 / 林华、王勇 / 中信出版社,中信出版集团 / 2016-8-25 / CNY 79.00
从数字货币及智能合约技术层面,解读了区块链技术在金融领域的运用。“如果你正在寻找一本在技术层面解释比特币是如何运作的,并且你有一定计算机科学和编程的基本知识,这本书应该很适合你。” 《区块链:技术驱动金融》回答了一系列关于比特币如何运用区块链技术运作的问题,并且着重讲述了各种技术功能,以及未来会形成的网络。比特币是如何运作的?它因何而与众不同?你的比特币安全吗?比特币用户如何匿名?区块链如何......一起来看看 《区块链技术驱动金融》 这本书的介绍吧!