from bottle.ext import sqlite as bottle_sqlite # pylint: disable-msg=F0401 from datetime import datetime from email.utils import formatdate from multiprocessing import Lock, Process, Event from os import getpid from socket import setdefaulttimeout from time import time from urllib import urlencode, urlopen from urlparse import urlunsplit from uuid import uuid4 import sqlite3 app = Bottle() app.timestamp_lock = Lock() app.fetcher_flag = Event() def fetcher(filename, base_url, event): """ Fetch titles for all enqueued URls, update db.""" print 'Fetcher process started as pid <%s>' % getpid() FETCHER_TIMEOUT = 5 setdefaulttimeout(FETCHER_TIMEOUT) tables = ('stack', 'viewed') c = sqlite3.connect(filename) c.row_factory = sqlite3.Row while event.is_set(): event.clear() for table in tables: rows = c.execute( 'SELECT * FROM ' +