From 00fdf12eff68c44f90d54ec8ea5117fafd5b5656 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Sat, 25 Aug 2012 01:38:50 +0000 Subject: [PATCH] The archive sqlite file used by the RESTful protocols is now opened within the RESTful thread itself. --- bin/weewx/restful.py | 9 ++++++--- bin/weewx/wxengine.py | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/weewx/restful.py b/bin/weewx/restful.py index 3bfcedd4..34856f34 100644 --- a/bin/weewx/restful.py +++ b/bin/weewx/restful.py @@ -17,6 +17,7 @@ import urllib2 import socket import time +import weewx.archive import weewx.units import weeutil.weeutil @@ -448,10 +449,10 @@ class RESTThread(threading.Thread): Basically, it watches a queue, and if anything appears in it, it publishes it. The queue should be populated with the timestamps of the data records to be published. """ - def __init__(self, archive, queue, station_list): + def __init__(self, archiveFilename, queue, station_list): """Initialize an instance of RESTThread. - archive: The archive database. Usually an instance of weewx.archive.Archive + archiveFilename: The file name for hte archive database. queue: An instance of Queue.Queue where the timestamps will appear @@ -461,7 +462,7 @@ class RESTThread(threading.Thread): # In the strange vocabulary of Python, declaring yourself a "daemon thread" # allows the program to exit even if this thread is running: self.setDaemon(True) - self.archive = archive + self.archive = weewx.archive.Archive(archiveFilename) self.queue = queue # Fifo queue where new records will appear self.station_list = station_list @@ -472,6 +473,7 @@ class RESTThread(threading.Thread): # A 'None' value appearing in the queue is our signal to exit if time_ts is None: + self.archive.close() return # This string is just used for logging: @@ -505,6 +507,7 @@ class RESTThread(threading.Thread): syslog.syslog(syslog.LOG_CRIT, " **** %s" % (e,)) weeutil.weeutil.log_traceback(" **** ") syslog.syslog(syslog.LOG_CRIT, " **** Thread terminating.") + self.archive.close() raise else: syslog.syslog(syslog.LOG_INFO, "restful: Published record %s to %s station %s" % (time_str, station.site, station.station)) diff --git a/bin/weewx/wxengine.py b/bin/weewx/wxengine.py index b2f0b8dc..3e031675 100644 --- a/bin/weewx/wxengine.py +++ b/bin/weewx/wxengine.py @@ -717,11 +717,10 @@ class StdRESTful(StdService): # Create an instance of weewx.archive.Archive archiveFilename = os.path.join(config_dict['Station']['WEEWX_ROOT'], config_dict['StdArchive']['archive_file']) - archive = weewx.archive.Archive(archiveFilename) # Create the queue into which we'll put the timestamps of new data self.queue = Queue.Queue() # Start up the thread: - self.thread = weewx.restful.RESTThread(archive, self.queue, station_list) + self.thread = weewx.restful.RESTThread(archiveFilename, self.queue, station_list) self.thread.start() syslog.syslog(syslog.LOG_DEBUG, "wxengine: Started thread for RESTful upload sites.")