我已经编写了python脚本扫描wifi并将数据发送到服务器,我设置了间隔值,所以它继续扫描并发送数据,它从config.txt文件中读取,我将间隔值设置为扫描,我也在我的配置文件中添加了yes/no,所以是no,它只扫描一次,如果是,它将根据间隔级别进行扫描。
我的代码如下
import time,.....
from threading import Event, Thread
class RepeatTimer(Thread):
def __init__(self, interval, function, iterations=0, args=[], kwargs={}):
Thread.__init__(self)
self.interval = interval
self.function = function
self.iterations = iterations
self.args = args
self.kwargs = kwargs
self.finished = Event()
def run(self):
count = 0
while not self.finished.is_set() and (self.iterations <= 0 or count < self.iterations):
self.finished.wait(self.interval)
if not self.finished.is_set():
self.function(*self.args, **self.kwargs)
count += 1
def cancel(self):
self.finished.set()
def scanWifi(self):
#scanning process and sending data done here
obj = JW()
if status == "yes":
t = RepeatTimer(int(intervalTime),obj.scanWifi)
t.start()
else:
obj.scanWifi()
一旦我打包了我的代码,它只在我将配置文件设置为“否”时运行,在这里它只扫描一次,但是当我将配置文件设置为“是”时,根本没有进展,所以我发现我的类repeattimer(timer)一旦构建就有问题,但不知道如何解决
有人能帮我吗
谢谢