码迷,mamicode.com
首页 > 编程语言 > 详细

基于python的交互式访问

时间:2018-01-03 11:34:06      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:class   locking   迁移   blocking   交互   屏幕   镜像   动态   blog   

应用迁移中遇到一些有特殊要求的应用,比如需要通过交互生成一些新的config文件,然后启动应用需要依赖于这些文件,这样在构建镜像的时候基本上是没有办法把这些文件固定的,因为他需要根据运行环境去进行动态注册生成,目前的解决方法如下:

1.写一段支持交互的python脚本,生成配置

#!/usr/bin/python

import subprocess
import time
import fcntl
import os

p = subprocess.Popen(["java","-jar","a.jar"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)

flags = fcntl.fcntl(p.stdout,fcntl.F_GETFL)
fcntl.fcntl(p.stdout,fcntl.F_SETZFL,flags| os.O_NONBLOCK)

time.sleep(2)
print p.stdout.read()
p.stdin.write("1\r\n")

开始调试时屏幕一直处于blocking状态,后来同事高手指导下加入NONBLOCK后才通过。

2.将python脚本放入tomcat运行的catalina.sh,让他在启动容器后,启动脚本一开始就运行

 

基于python的交互式访问

标签:class   locking   迁移   blocking   交互   屏幕   镜像   动态   blog   

原文地址:https://www.cnblogs.com/ericnie/p/8182156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!