* Simplified logging helper.
* Fixed think-o in how to close the CollectionWrapper inside a ThreadingCollectionWrapper.
This commit is contained in:
parent
f891a939c3
commit
9207f3bce4
@ -478,9 +478,7 @@ class CardHandler(RestHandlerBase):
|
|||||||
def make_app(global_conf, **local_conf):
|
def make_app(global_conf, **local_conf):
|
||||||
# setup the logger
|
# setup the logger
|
||||||
from AnkiServer.utils import setup_logging
|
from AnkiServer.utils import setup_logging
|
||||||
logging_config_file = local_conf.get('logging.config_file')
|
setup_logging(local_conf.get('logging.config_file'))
|
||||||
if logging_config_file:
|
|
||||||
setup_logging(logging_config_file)
|
|
||||||
|
|
||||||
return RestApp(
|
return RestApp(
|
||||||
data_root=local_conf.get('data_root', '.'),
|
data_root=local_conf.get('data_root', '.'),
|
||||||
|
|||||||
@ -114,11 +114,21 @@ class ThreadingCollectionWrapper(object):
|
|||||||
if self._thread is not None:
|
if self._thread is not None:
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
|
|
||||||
|
#
|
||||||
# Mimic the CollectionWrapper interface
|
# Mimic the CollectionWrapper interface
|
||||||
|
#
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
"""Non-op. The collection will be opened on demand."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.stop()
|
"""Closes the underlying collection without stopping the thread."""
|
||||||
|
|
||||||
|
def _close(col):
|
||||||
|
self.wrapper.close()
|
||||||
|
self.execute(_close, waitForReturn=False)
|
||||||
|
|
||||||
def opened(self):
|
def opened(self):
|
||||||
return self.wrapper.opened()
|
return self.wrapper.opened()
|
||||||
|
|
||||||
@ -152,15 +162,18 @@ class ThreadingCollectionManager(CollectionManager):
|
|||||||
for path, thread in self.collections.items():
|
for path, thread in self.collections.items():
|
||||||
if thread.running and thread.wrapper.opened() and thread.qempty() and cur - thread.last_timestamp >= self.monitor_inactivity:
|
if thread.running and thread.wrapper.opened() and thread.qempty() and cur - thread.last_timestamp >= self.monitor_inactivity:
|
||||||
logging.info('Monitor is closing collection on inactive CollectionThread[%s]', thread.path)
|
logging.info('Monitor is closing collection on inactive CollectionThread[%s]', thread.path)
|
||||||
def closeCollection(wrapper):
|
thread.close()
|
||||||
wrapper.close()
|
|
||||||
thread.execute(closeCollection, waitForReturn=False)
|
|
||||||
time.sleep(self.monitor_frequency)
|
time.sleep(self.monitor_frequency)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
# TODO: stop the monitor thread!
|
# TODO: stop the monitor thread!
|
||||||
|
|
||||||
# This will stop all the collection threads
|
# stop all the threads
|
||||||
|
for path, col in self.collections.items():
|
||||||
|
del self.collections[path]
|
||||||
|
col.stop()
|
||||||
|
|
||||||
|
# let the parent do whatever else it might want to do...
|
||||||
super(ThreadingCollectionManager, self).shutdown()
|
super(ThreadingCollectionManager, self).shutdown()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,15 +1,18 @@
|
|||||||
|
|
||||||
def setup_logging(config_file):
|
def setup_logging(config_file=None):
|
||||||
"""Setup logging based on a config_file."""
|
"""Setup logging based on a config_file."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# monkey patch the logging.config.SMTPHandler if necessary
|
if config_file is not None:
|
||||||
import sys
|
# monkey patch the logging.config.SMTPHandler if necessary
|
||||||
if sys.version_info[0] == 2 and sys.version_info[1] == 5:
|
import sys
|
||||||
import AnkiServer.logpatch
|
if sys.version_info[0] == 2 and sys.version_info[1] == 5:
|
||||||
|
import AnkiServer.logpatch
|
||||||
|
|
||||||
# load the config file
|
# load the config file
|
||||||
import logging.config
|
import logging.config
|
||||||
logging.config.fileConfig(config_file)
|
logging.config.fileConfig(config_file)
|
||||||
|
else:
|
||||||
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user