python执行子进程实现进程间通信的好办法!

来源:3lian.com时间:2018-05-11 14:02:22

python执行子进程实现进程间通信的好办法!

  

1

  

2

  

3

  

4

  

5

  

6

  

7

  

  

  

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:

  ?

  

1

  

2

  

3

  

4

  

  

  

import sys

  

print('receive...')

  

s = sys.stdin.readline()

  

print('get:', len(s), s)

  

  

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

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站) 联系邮箱:[email protected]