gpt4 book ai didi

Python,属性错误: RunCmd instance has no attribute 'p' for delta debug

转载 作者:太空宇宙 更新时间:2023-11-03 18:57:28 25 4
gpt4 key购买 nike

我有一个产生错误的 Python 程序:

File "myTest.py", line 34, in run
self.output = self.p.stdout
AttributeError: RunCmd instance has no attribute 'p'

Python 代码:

class RunCmd():

def __init__(self, cmd):
self.cmd = cmd

def run(self, timeout):
def target():
self.p = sp.Popen(self.cmd[0], self.cmd[1], stdin=sp.PIPE,
stdout=sp.PIPE, stderr=sp.STDOUT)

thread = threading.Thread(target=target)
thread.start()
thread.join(timeout)

if thread.is_alive():
print "process timed out"
self.p.stdin.write("process timed out")
self.p.terminate()
thread.join()

self.output = self.p.stdout #self.p.stdout.read()?
self.status = self.p.returncode

def getOutput(self):
return self.output

def getStatus(self):
return self.status

这是整个回溯。

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "myTest.py", line 18, in target
self.p = sp.Popen(self.cmd, stdin=PIPE,
NameError: global name 'PIPE' is not defined

Traceback (most recent call last):
File "myTest.py", line 98, in <module>
c = mydd.ddmin(deltas) # Invoke DDMIN
File "/home/DD.py", line 713, in ddmin
return self.ddgen(c, 1, 0)
File "/home/DD.py", line 605, in ddgen
outcome = self._dd(c, n)
File "/home/DD.py", line 615, in _dd
assert self.test([]) == self.PASS
File "/home/DD.py", line 311, in test
outcome = self._test(c)
File "DD.py", line 59, in _test
test.run(3)
File "DD.py", line 30, in run
self.status = self.p.returncode
AttributeError: 'RunCmd' object has no attribute 'p'

这个错误是什么意思?它想告诉我什么?

最佳答案

您没有给出所有错误消息。线程中的代码失败是因为你对Popen的调用是错误的,它应该是:

def target():
self.p = sp.Popen(self.cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT)

当线程失败时,它不会设置“p”变量,这就是您收到所讨论的错误消息的原因。

关于Python,属性错误: RunCmd instance has no attribute 'p' for delta debug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16964461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com