【发布时间】:2013-07-15 13:51:31
【问题描述】:
我的脚本在过去 3 个月内一直正常运行。服务器上周一宕机了,从那以后我的脚本就停止工作了。脚本挂在coords = p.communicate()[0].split()。
这是脚本的一部分:
class SelectByLatLon(GridSelector):
def __init__(self, from_lat, to_lat, from_lon, to_lon):
self.from_lat = from_lat
self.to_lat = to_lat
self.from_lon = from_lon
self.to_lon = to_lon
def get_selection(self, file):
p = subprocess.Popen(
[
os.path.join(module_root, 'bin/points_from_latlon.tcl'),
file,
str(self.from_lat), str(self.to_lat), str(self.from_lon), str(self.to_lon)
],
stdout = subprocess.PIPE
)
coords = p.communicate()[0].split()
return ZGridSelection(int(coords[0]), int(coords[1]), int(coords[2]), int(coords[3]))
当我在另一台服务器上运行脚本时,一切正常。
我可以用其他东西代替p.communicate()[0].split() 吗?
【问题讨论】:
-
看起来你的 tcl 脚本正在挂起。修复它。
-
它在
communicate()上是否“挂起”无限长,即子进程不会退出(你应该监控它)吗? “不同的”服务器通常意味着程序运行环境的许多部分是不同的。可能是(子进程)程序挂起,因为它需要来自标准输入的输入。尝试通过stdin=subprocess.PIPE打开到标准输入的管道,并通过p.communicate("\n")为子进程提供一些输入(例如换行符)。如果这有帮助,我们稍后可以弄清楚究竟是什么触发了这种差异。 -
Martineau 你是对的。 TCL 脚本导致问题。我不知道为什么。在过去的 3 个月中,相同的脚本一直在正常工作。我想弄清楚。
标签: python subprocess popen communicate