<p>在下面的代码中,我正在创建一个线程,它打开一个名为candump的函数。Candump监视输入通道,并在数据进入时将值返回到std out。在</p>
<p>我想做的是控制何时终止(即cansend之后的固定时间)。在看过文档之后,join似乎是正确的选择?在</p>
<p>我不确定。有什么想法吗?在</p>
<pre><code>import threading
from subprocess import call, Popen,PIPE
import time
delay=1
class ThreadClass(threading.Thread):
def run(self):
start=time.time()
proc=Popen(["candump","can0"],stdout=PIPE)
while True:
line=proc.stdout.readline()
if line !='':
print line
t = ThreadClass()
t.start()
time.sleep(.1)
call(["cansend", "can0", "-i", "0x601", "0x40", "0xF6", "0x60", "0x01", "0x00", "0x00", "0x00", "0x00"])
time.sleep(0.01)
#right here is where I want to kill the ThreadClass thread
</code></pre>