【问题标题】:Pydev Eclipse executes previously executed program before executing current programPydev Eclipse 在执行当前程序之前执行先前执行的程序
【发布时间】:2017-12-04 17:35:56
【问题描述】:

我有一个包含多个 pydev 模块程序的项目。没有一个模块相互链接或导入到其他模块中。都是独立的模块。 我看到两个程序存在问题,即:“CmdOnRemoteServer”和“ipaddress”

当我执行程序“CmdOnRemoteServer”程序时,控制台打印先前/旧程序“ipaddress”的输出,然后跳转到当前程序“CmdOnRemoteServer”并打印输出。 我可以通过将程序调试并在两个程序中设置断点来找到这种行为。

在 Preferences>>Run/Debug>>Launching 中,选择的选项是“Launch the selected resource or active editor”和“If not launchable>>Launch the previous launch the application”

我在“CmdOnRemoteServer”中添加了 'if ____name____ == "____main____":' 代码,但这也没有帮助。 我附上了显示主线程中列出的两个程序的调试屏幕截图。

有人可以帮我解决这个问题吗?

根据要求,将代码添加到问题中:

if __name__ == "__main__":
    remoteServer=winrm.Session("IDCQEAM190.amdom009.lab", auth = ("Administrator", "Control123"))
remoteCMD = remoteServer.run_cmd("ipconfig", ["/all"])

myfile = open(r"C:\Users\pshastri\Desktop\remoteServer.txt", "w")
myfile.write(remoteCMD.std_out)
myfile.close()

myfile = open(r"C:\Users\pshastri\Desktop\remoteServer.txt", "r")
ipPatt = "IPv4 Address[\.\s]{1,}:\s[\d+\.]{1,}"
hostPatt = "Host Name [\.\s]{1,}: [A-Za-z0-9]+"
domPatt = "Primary Dns Suffix [\.\s]{1,}: [A-Za-z0-9]+\.[A-Za-z0-9]+"
myfile.seek(0)
ipReg = re.findall(ipPatt, myfile.read())
myfile.seek(0)
hostReg = re.findall(hostPatt, myfile.read())
myfile.seek(0)
domReg = re.findall(domPatt, myfile.read())
print "".join(ipReg), "\n", "".join(hostReg), "\n", "".join(domReg)

【问题讨论】:

  • 您是否准确添加了if ____name____ == "____main____": ?因为如果是这样,这是无效的 python 语法,你应该输入if __name__ == "__main__": 。另外,您可以为 CmdOnRemoteServer 添加代码吗?
  • 不是因为这里的文本格式。如果我输入了不正确的语法,我会遇到一些编译错误。将代码添加到主要问题。

标签: python eclipse pydev


【解决方案1】:

正如您在调试堆栈跟踪中看到的那样,问题似乎是您的程序 (CmdOnRemoteServer) 最终出现在 Python 标准库导入 ipaddress 的链中strong> 模块(因此,要修复错误,请将您的 ipaddress 模块重命名为其他名称,因为该名称已在标准库中使用)。

【讨论】:

  • 我确实将 ipaddress 文件重命名为 myaddress。这一次我没有在调试跟踪中看到该文件,即使我已经在文件中放置了断点。但是 myaddress 文件的输出在打印 CmdOnRemoteServer 输出之前打印
  • 好吧,我不能真正调试你那里的东西......我的建议是你在它打印的地方引发一个异常并查看堆栈跟踪以尝试发现可能有什么问题(你可能需要删除所有 .pyc 文件,以确保没有前一个模块的剩余部分)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
相关资源
最近更新 更多