try except question - serious foo bar question, and pulling my hair

Discussion in 'Python' started by Laszlo Nagy, Feb 24, 2009.

  1. Laszlo Nagy

    Laszlo Nagy Guest

    Given this class below:

    import Queue
    import threading
    from sorb.util.dumpexc import dumpexc
    import waitablemixin


    PREFETCH_SIZE = 10

    class Feeder(threading.Thread,waitablemixin.WaitableMixin):
    def __init__(self,connection_manager):
    self.cm = connection_manager
    self.expired_asins = Queue.Queue()
    self.logger = self.cm.loggerfactory.get_logger("feeder")
    threading.Thread.__init__(self)

    def run(self):
    try:
    try:
    d = self.cm.create_dispatcher()
    try:
    od_producer = d.locate('od_producer')
    while not self.cm.stop_requested.isSet():
    try:
    items = od_producer.getsomeasins()
    if items:
    self.logger.info("Got %d items to
    process",len(items))
    for item in items:
    self.expired_asins.put(item)
    if self.expired_asins.qsize()>PREFETCH_SIZE:
    while
    (self.expired_asins.qsize()>PREFETCH_SIZE) and \
    not self.cm.stop_requested.isSet():
    self.logger.info(
    "%s (>%s) items in the
    queue, waiting...",
    self.expired_asins.qsize(),
    PREFETCH_SIZE
    )
    self.waitsome(1)
    else:
    self.logger.info("No more items to
    process, will wait 5 minutes.")
    self.waitsome(5*60)
    except Exception,e:
    self.logger.error("Could not get asins:
    %s",dumpexc(e) )
    self.logger.error("Will retry in 10 seconds.")
    self.waitsome(10)
    finally:
    d.close()
    except Exception,e:
    self.cm.stop_requested.set()
    self.logger.error(dumpexc(e))
    finally:
    self.logger.error("Feeder stopped. stop_requested =
    %s",str(self.cm.stop_requested.isSet()))


    How in the hell can I get the following log output:

    2009-02-24 11:42:14,696 INFO .feeder Got 5 items to process
    2009-02-24 11:42:14,732 INFO .feeder Got 5 items to process
    2009-02-24 11:42:14,733 INFO .feeder 15 (>10) items in the queue, waiting...
    2009-02-24 11:42:15,740 INFO .feeder 15 (>10) items in the queue, waiting...
    2009-02-24 11:42:16,965 ERROR .feeder Feeder stopped. stop_requested = False

    It seems impossible to me. The while loop should only exit if
    stop_requested becomes set, OR if an exception is raised. However, all
    exceptions are cought and logged. But there are no exceptions logged.
    And stop_requested is NOT SET. (see the last line in the log).

    What is happening here?
    Laszlo Nagy, Feb 24, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Salerno
    Replies:
    20
    Views:
    843
    John Salerno
    Aug 11, 2006
  2. Jonathan Bartlett
    Replies:
    7
    Views:
    451
    Peter Nilsson
    Jul 8, 2005
  3. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    367
  4. Wejn
    Replies:
    2
    Views:
    117
    Michal
    Nov 29, 2003
  5. Max Williams
    Replies:
    10
    Views:
    200
    Max Williams
    Dec 15, 2007
Loading...

Share This Page