Skip to content

Commit

Permalink
fix shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
roe-dl committed May 8, 2023
1 parent 55175a4 commit 32d9e4e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
35 changes: 30 additions & 5 deletions bin/user/airQ_corant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"""

VERSION = "0.9b2"
VERSION = "0.9b3"

# imports for airQ
import base64
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(self, q, name, address, passwd, log_success, log_failure, query_int
self.running = True
loginf("thread '%s', host '%s': initialized" % (self.name,self.address))

def shutdown(self):
def shutDown(self):
""" stop thread """
self.running = False

Expand Down Expand Up @@ -453,10 +453,35 @@ def _create_thread(self, thread_name, address, passwd, prefix, altitude, query_i
self.threads[thread_name]['thread'].start()
return True

def shutdown(self):
def shutDown(self):
for ii in self.threads:
loginf("shutting down connection to '%s'" % ii)
self.threads[ii]['thread'].shutdown()
try:
loginf("shutting down connection to '%s'" % ii)
self.threads[ii]['thread'].shutDown()
except:
pass
# wait at max 10 seconds for shutdown to complete
timeout = time.time()+10
for ii in self.threads:
try:
w = timeout-time.time()
if w<=0: break
self.threads[ii]['thread'].join(w)
if self.threads[ii]['thread'].is_alive():
logerr("unable to shutdown thread '%s'" % self.threads[ii]['thread'].name)
except:
pass
# report threads that are still alive
_threads = [ii for ii in self.threads]
for ii in _threads:
try:
if self.threads[ii]['thread'].is_alive():
logerr("unable to shutdown thread '%s'" % self.threads[ii]['thread'].name)
del self.threads[ii]['thread']
del self.threads[ii]['queue']
del self.threads[ii]
except:
pass

def new_loop_packet(self, event):
for ii in self.threads:
Expand Down
14 changes: 10 additions & 4 deletions bin/user/airq_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ def setConfig(config_dict, device, data):
<p class="lastupdate">$current.dateTime</p>
</div>
<div id="reports">
%s </div>
</div>
'''
HTML_HEAD_ID='''#if $current.%s.has_data
ID: $current.%s.raw
#end if
<br/>
#if $current.%s.has_data
$current.%s.raw
</div>
</div>
#end if
'''
HTML_FOOT='''
</body>
Expand Down Expand Up @@ -689,7 +694,7 @@ def createSkin(config_path, config_dict, db_binding):
airqlang.close()
print("creating %s" % os.path.join(airq_skin_path,'index.html.tmpl'))
with open(os.path.join(airq_skin_path,'index.html.tmpl'),"w") as file:
file.write(HTML_HEAD)
file.write(HTML_HEAD % (_gettext_text(None,"'lang'",gettext_style),""))
file.write('<ul>')
for dev in config_dict['airQ'].sections:
file.write('<li><a href="%s.html">%s</a></li>' % (dev,dev))
Expand Down Expand Up @@ -748,7 +753,8 @@ def create_template(dev_dict, dev, airq_skin_path, sensors, obstypes, gettext_st
fn = os.path.join(airq_skin_path,fn)
print("creating %s" % fn)
with open(fn,"w") as file:
file.write(HTML_HEAD % (_gettext_text(None,"'lang'",gettext_style),obstype_with_prefix('airqDeviceID',dev_dict.get('prefix')),obstype_with_prefix('airqStatus',dev_dict.get('prefix'))))
id_txt = HTML_HEAD_ID % (obstype_with_prefix('airqDeviceID',dev_dict.get('prefix')),obstype_with_prefix('airqDeviceID',dev_dict.get('prefix')),obstype_with_prefix('airqStatus',dev_dict.get('prefix')),obstype_with_prefix('airqStatus',dev_dict.get('prefix')))
file.write(HTML_HEAD % (_gettext_text(None,"'lang'",gettext_style),id_txt))
file.write('''
<div id="contents">
<div id="widget_group">
Expand Down
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
* some error handling improvements
* fixed bug reading altitude in config, thanks to Hartmut
* adapt to WeeWX 4.6.0b2 function style $gettext in --create-skin
0.9b3
* fix shutdown
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def loader():
class AirqInstaller(ExtensionInstaller):
def __init__(self):
super(AirqInstaller, self).__init__(
version="0.9b2",
version="0.9b3",
name='airQ',
description='Service to retrieve data from the airQ device of Corant GmbH',
author="Johanna Roedenbeck",
Expand Down

0 comments on commit 32d9e4e

Please sign in to comment.