Python中的OS模块提供了与操作系统进行交互的功能。操作系统属于Python的标准实用程序模块。该模块提供了使用依赖于操作系统的功能的便携式方法。

如果文件名和路径无效或无法访问,或者其他类型正确但操作系统不接受的参数,则os模块中的所有函数都会引发OSError。

os.pipe()Python中的方法用于创建管道。管道是一种将信息从一个进程传递到另一个进程的方法。它仅提供one-way通信,并且传递的信息由系统保留,直到被接收进程读取为止。

用法: os.pipe()

参数:不需要参数

返回类型:此方法返回分别可用于读取和写入的一对文件描述符(r,w)。

代码:os.pipe()方法的使用

# Python program to explain os.pipe() method

# importing os module

import os

# Create a pipe

r, w = os.pipe()

# The returned file descriptor r and w

# can be used for reading and

# writing respectively.

# We will create a child process

# and using these file descriptor

# the parent process will write

# some text and child process will

# read the text written by the parent process

# Create a child process

pid = os.fork()

# pid greater than 0 represents

# the parent process

if pid > 0:

# This is the parent process

# Closes file descriptor r

os.close(r)

# Write some text to file descriptor w

print("Parent process is writing")

text = b"Hello child process"

os.write(w, text)

print("Written text:", text.decode())

else:

# This is the parent process

# Closes file descriptor w

os.close(w)

# Read the text written by parent process

print("\nChild Process is reading")

r = os.fdopen(r)

print("Read text:", r.read())

输出:

Parent process is writing

Text written:Hello child process

Child Process is reading

Text read:Hello child process

python pipe_Python os.pipe()用法及代码示例相关推荐

  1. python getostime_Python os.getrandom()用法及代码示例

    Python中的OS模块提供了与操作系统进行交互的功能.操作系统属于Python的标准实用程序模块.该模块提供了使用依赖于操作系统的功能的便携式方法. os.getrandom()方法用于生成适合加密 ...

  2. python chmod_Python os.chmod用法及代码示例

    Python中的os.chmod()方法用于将路径模式更改为数字模式. 用法: os.chmod(path, mode) 参数: path - path name of the file or dir ...

  3. python中的os abort_Python os.abort()用法及代码示例

    Python中的OS模块提供了与操作系统进行交互的功能.操作系统属于Python的标准实用程序模块.该模块提供了使用依赖于操作系统的功能的便携式方法. os.abort()Python中的方法用于生成 ...

  4. python macos listdir_Python os.listdir()用法及代码示例

    python中的os.listdir()方法用于获取指定目录中所有文件和目录的列表.如果我们未指定任何目录,则将返回当前工作目录中的文件和目录列表. 用法: os.listdir(path) 参数: ...

  5. matlab中jet的例子,Python matplotlib.pyplot.jet()用法及代码示例

    Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展. Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口. matplotli ...

  6. matlab怎么设clim,Python Matplotlib.pyplot.clim()用法及代码示例

    Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展. Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口.在Pyplot中可以 ...

  7. python imshow cmap,Python matplotlib.pyplot.imshow()用法及代码示例

    Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展. Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口. matplotli ...

  8. python pandas astype,Python Pandas DataFrame.astype()用法及代码示例

    Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统. Pandas是其中的一种,使导入和分析数据更加容易. DataFrame.astype()方法 ...

  9. python numpy allclose用法及代码示例

    python numpy allclose用法及代码示例 用法: numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) 如果两个数 ...

  10. python把图片转化为素描画_python如何将图片转换素描画 python将图片转换素描画代码示例...

    python如何将图片转换素描画?本篇文章小编给大家分享一下python将图片转换素描画代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 代码如 ...

最新文章

  1. 技术人如何做职场沟通?
  2. 如何搭建VUE开发环境
  3. jquery源码学习笔记一:总体结构
  4. python简单代码表白-python浪漫表白源码
  5. Windows下使用Dev-C++开发基于pthread.h的多线程程序
  6. Python 全局变量和局部变量迷惑人的小示例
  7. Go中bytes.Buffer理解
  8. mesh threejs 属性_threeJS创建mesh,创建平面,设置mesh的平移,旋转、缩放、自传、透明度、拉伸...
  9. jax-rs jax-ws_JAX-RS 2.x与Spring MVC:返回对象列表的XML表示
  10. Couchbase:使用Twitter和Java创建大型数据集
  11. ajax访问遇到Session失效问题
  12. “10 倍工程师”引争议,程序员再被妖魔化?
  13. 入坑codewars第五天-Dubstep、Regex validate PIN code
  14. 乐优商城(01)--项目启动
  15. android学习和广告平台赚钱
  16. 毒你没商量!DOC病毒原理完全解析(转)
  17. Opencv中的convertTo
  18. 【集体智慧编程】第二章、提供推荐
  19. 音乐独奏,心情忧伤。
  20. 科班和非科班都适用的 Java 学习路线

热门文章

  1. 优秀架构师是如何学习开源项目的?
  2. echarts柱形图超炫颜色搭配
  3. Bert源代码(二)模型
  4. 电脑下载了自动捆绑怎么办?一招秒杀!
  5. 坚持十年博客写作,不忘初心,方得始终
  6. 2021年茶艺师(初级)考试试卷及茶艺师(初级)模拟考试
  7. 联通的G网和C网分别是什么意思?
  8. pcie转m2装系统win10_m.2固态硬盘怎么安装win10系统
  9. 看两宋风云,搞清了4个之前对两宋历史认识错误的地方
  10. 盾神与积木游戏 (贪心典例)