Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 98295 invoked from network); 7 Feb 2010 23:03:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Feb 2010 23:03:03 -0000 Received: (qmail 70537 invoked by uid 500); 7 Feb 2010 23:03:03 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 70450 invoked by uid 500); 7 Feb 2010 23:03:03 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 70441 invoked by uid 500); 7 Feb 2010 23:03:03 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 70438 invoked by uid 99); 7 Feb 2010 23:03:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Feb 2010 23:03:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Feb 2010 23:02:50 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 3CDBA16E2F; Sun, 7 Feb 2010 23:02:29 +0000 (GMT) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Sun, 07 Feb 2010 23:02:29 -0000 Message-ID: <20100207230229.18662.27339@eos.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Trivial_Update_of_=22Regenerating=5Fviews=5F?= =?utf-8?q?on=5Fupdate=22_by_JamesArthur?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for c= hange notification. The "Regenerating_views_on_update" page has been changed by JamesArthur. The comment on this change is: Ah yes, the actual version. http://wiki.apache.org/couchdb/Regenerating_views_on_update?action=3Ddiff&r= ev1=3D6&rev2=3D7 -------------------------------------------------- import logging logging.basicConfig(level=3Dlogging.INFO) = - import fcntl import os import re + import signal import sys import time import urllib2 = from threading import Thread = + flags =3D { - is_running =3D True + 'is_running': True + } + = changed_docs =3D {} = class ViewUpdater(object): @@ -166, +169 @@ ] } } - = + = def start(self): Thread(target=3Dself._run).start() = = def _run(self): """Loop, checking for enough ``changed_docs`` to trigger a - request to CouchDB to re-index. + request to couchdb to re-index. """ = - global is_running - while is_running: + while flags['is_running']: try: for db_name, number_of_docs in changed_docs.items(): if number_of_docs >=3D self.MIN_NUM_OF_CHANGED_DOCS: @@ -195, +197 @@ urllib2.urlopen(url) time.sleep(self.PAUSE) except Exception: - is_running =3D False + flags['is_running'] =3D False raise = = @@ -210, +212 @@ = DB_NAME_EXPRESSION =3D re.compile(r'\"db\":\"(\w+)\"') = - def __init__(self): - """Make stdin a non-blocking file - """ - = - fd =3D sys.stdin.fileno() - fl =3D fcntl.fcntl(fd, fcntl.F_GETFL) - fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) - = - = - = - def run(self): + def _run(self): """Consume update notifications from stdin. """ = - global is_running - while is_running: + while flags['is_running']: try: data =3D sys.stdin.readline() except: continue else: if not data: # exit - is_running =3D False + flags['is_running'] =3D False break result =3D self.DB_NAME_EXPRESSION.search(data) if result: @@ -249, +240 @@ = = = + def start(self): + t =3D Thread(target=3Dself._run) + t.start() + return t + = + = + = = = def main(): @@ -256, +254 @@ consumer =3D NotificationConsumer() updater =3D ViewUpdater() updater.start() + t =3D consumer.start() try: - consumer.run() + while flags['is_running']: + t.join(10) except KeyboardInterrupt, err: - is_running =3D False + flags['is_running'] =3D False + = = = =20