2
使用键盘停止具有无限循环的PyQGIS脚本?
因此,我编写了一个脚本,该脚本在一定时间间隔(使用time.sleep(5)每5秒一次)中使用“ while True:”一次又一次地执行我想要的操作。到目前为止,还不错,但是当我想要停止它时,我只是做不到。 我尝试了Control + C,Control + Break,Escape,但实际上它忽略了我的键盘。停止它的唯一方法是关闭QGIS。有任何想法吗?此外,当脚本命中time.sleep(5)时,QGIS会滞后5秒钟,并且无法进行平移,但是我认为这是正常的。 这是我的脚本: from PyQt4.QtGui import * from PyQt4.QtCore import * from qgis.core import * from qgis.utils import iface import time while True: def change_color(): active_layer = iface.activeLayer() pipeline=[] txt=open('C:/users/stelios/desktop/project/Sensor.txt','r') for line in txt.readlines(): pipeline.append(line.split()) print pipeline pipeline2=[] for label,color in pipeline: if "0" …