我有3个功能。 listener
函数每10秒钟调用一次函数check_url
。如果此功能成功检查,则调用destroy
函数。 destroy
函数来完成它的工作后,我要终止的listener
我试着用finish_control
可变虽然真正的循环没有结束
def listener(url):
while True:
if finish_control == 1:
break
check_url(url)
sleep(10)
def check_url(url):
print ("Status: Listening")
response = urllib.request.urlopen(url)
data = response.read()
text = data.decode('utf-8')
if text == '1':
print("--Action Started!--")
destroy(argv.location)
def destroy(location):
#some work
print("---Action completed!---")
finish_control = 1
但是这里面listener
while循环不会终止做到这一点。我也试过
while (finish_control == 0):
还有同样的问题。如何在destroy
完成工作后停止工作?
'listener()'函数不知道'finish_control'变量 – fedorqui 2015-03-30 19:32:09