python执行子进程实现进程间通信的方法

yipeiwu_com6年前Python基础

本文实例讲述了python执行子进程实现进程间通信的方法。分享给大家供大家参考。具体实现方法如下:

a.py:

import subprocess, time
subproc = subprocess.Popen(['c:\python31\python.exe', 'c:/b.py'], stdin=subprocess.PIPE, shell=True) 
time.sleep(0.5)
print('start')
subproc.stdin.write('data\n')
subproc.communicate('data\n')
print('end')

b.py:

import sys
print('receive...')
s = sys.stdin.readline()
print('get:', len(s), s)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

在python中实现将一张图片剪切成四份的方法

如下所示: import cv2 # [1]导入OpenCv开源库 import numpy as np image_path = "F:\\111111111111111111...

python中的turtle库函数简单使用教程

python中的turtle库函数简单使用教程

具体内容如下所示: 参考案例: import turtle d=0 for i in range(4): turtle.fd(200) #或者写成turtle.fo...

详解Python3注释知识点

Python3 注释 确保对模块, 函数, 方法和行内注释使用正确的风格 Python中的注释有单行注释和多行注释: Python中单行注释以 # 开头,例如:: # 这是一个...

Python简单删除列表中相同元素的方法示例

本文实例讲述了Python简单删除列表中相同元素的方法。分享给大家供大家参考,具体如下: 去除列表中重复的元素,非常简单,直接上代码: a = [11, 21, 3, 4, 3, 2...

如何给Python代码进行加密

这篇文章主要介绍了如何给Python代码进行加密,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 去年11月在PyCon China 2...