python中子进程间实现通信的方法介绍
June 26, 2015
python中子进程间实现通信的方法是如何来实现的呢?下面的内容将会通过具体的实例来演示python中子进程间实现通信的方法的实现方法及相关技巧:
本文实例讲述了python执行子进程实现进程间通信的方法。分享给大家供大家参考。具体实现方法如下:
a.py:
import subprocess, time
subproc = subprocess.Popen(['c:python31python.exe', 'c:/b.py'], stdin=subprocess.PIPE, shell=True)
time.sleep(0.5)
print('start')
subproc.stdin.write('datan')
subproc.communicate('datan')
print('end')
b.py:
import sys
print('receive...')
s = sys.stdin.readline()
print('get:', len(s), s)
python中子进程间实现通信的方法就是这样,欢迎大家参考。。。。
0 Comments