Ignore:
Timestamp:
Jan 21, 2012, 11:14:07 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
75928fe
Parents:
3cb6c7b
git-author:
Jessica B. Hamrick <jhamrick@…> (01/21/12 23:12:03)
git-committer:
Jessica B. Hamrick <jhamrick@…> (01/21/12 23:14:07)
Message:

Fix a few more bugs in printer.py and update test cases for printer.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/server/printer.py

    r7e29e6a rd42236e  
    66import time
    77import threading
    8 import heapq
    98import traceback
    109import sys
     
    102101        self._running = True
    103102        while self._running:
    104             try:
    105                 with self.lock:
     103            with self.lock:
     104                try:
    106105                    if self.current_job is None:
    107106                        self.start_job()
    108107                    elif self.current_job.is_done:
    109108                        self.complete_job()
    110             except:
    111                 logger.fatal(traceback.format_exc())
    112                 sys.exit(1)
     109                except:
     110                    self._running = False
     111                    logger.fatal(traceback.format_exc())
     112                    break
    113113            time.sleep(0.1)
    114114
    115115    def stop(self):
    116116        with self.lock:
     117            for job in self.jobs.keys():
     118                try:
     119                    self.jobs[job].abort()
     120                    del self.jobs[job]
     121                except InvalidJobStateException:
     122                    pass
     123               
    117124            self._running = False
    118125        if self.ident is not None and self.isAlive():
     
    159166    @sync
    160167    def state(self):
    161         if self.is_running and self.current_job is not None:
    162             state = States.PROCESSING
    163         elif self.is_running and len(self.pending_jobs) == 0:
    164             state = States.IDLE
     168        if self.is_running and not self.paused:
     169            if len(self.active_jobs) > 0:
     170                state = States.PROCESSING
     171            else:
     172                state = States.IDLE
    165173        else:
    166174            state = States.STOPPED
     175
    167176        return state
    168177
     
    194203        if not self.paused and self.current_job is None:
    195204            try:
    196                 job_id = heapq.heappop(self.pending_jobs)
     205                job_id = self.pending_jobs.pop(0)
    197206                self.current_job = self.get_job(job_id)
    198207                self.current_job.play()
    199208            except IndexError:
    200                 self.current_job = None
    201             except InvalidJobStateException:
    202                 heapq.heappush(self.pending_jobs, self.current_job.id)
    203209                self.current_job = None
    204210                   
     
    530536
    531537    @sync
    532     def create_job(self, requesting_user_name=None, job_name=None,
    533                    job_k_octets=None):
     538    def create_job(self, requesting_user_name=None,
     539                   job_name=None, job_k_octets=None):
    534540
    535541        self.assert_running()
     
    544550
    545551        self.jobs[job_id] = job
    546         self.pending_jobs.append(job_id)
    547        
    548552        return job_id
    549553
     
    617621        job = self.get_job(job_id)
    618622        job.spool(document)
    619 
     623        if 'dryrun' in self.config and self.config['dryrun']:
     624            job.player._dryrun = True
     625        self.pending_jobs.append(job_id)
     626       
    620627    @sync
    621628    def send_uri(self, job_id, document_uri, document_name=None,
     
    628635        # XXX: need to validate URI
    629636        # XXX: need to deal with the URI stream?
     637
    630638        #job.spool_uri(document_uri)
    631 
     639        #if 'dryrun' in self.config and self.config['dryrun']:
     640        #    job.player._dryrun = True
     641        #self.pending_jobs.append(job_id)
     642       
    632643    @sync
    633644    def get_job_attributes(self, job_id, requested_attributes=None):
Note: See TracChangeset for help on using the changeset viewer.