Changeset 1856

Show
Ignore:
Timestamp:
02/11/08 13:49:09 (2 months ago)
Author:
duncan
svm:headrev:

cc3e1ea1-1e01-0410-8d68-8b121e83a9d5:11138
Message:

The childapp log file was being opened twice, once in the main thread and once in the capture thread.
This fix removes the open in the main thread.

Also the application log is timestamped as it is difficult to debug when the file is overwritten.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • freevo/src/childapp.py

    r1748 r1856  
    8585 
    8686            command = ('%s %s' % (config.RUNAPP, app)).strip() 
    87             debug_name = app[:app.find(' ')] 
     87            app_name = app[:app.find(' ')] 
    8888 
    8989        else: 
     
    104104                command = app 
    105105 
    106             debug_name = app[0] 
    107  
    108         if debug_name.rfind('/') > 0: 
    109             debug_name = debug_name[debug_name.rfind('/')+1:] 
     106            app_name = app[0] 
     107 
     108        if app_name.rfind('/') > 0: 
     109            app_name = app_name[app_name.rfind('/')+1:] 
    110110        else: 
    111             debug_name = debug_name 
     111            app_name = app_name 
    112112 
    113113        if debugname: 
    114             debug_name = debugname 
     114            app_name = debugname 
    115115 
    116116        if doeslogging or config.DEBUG_CHILDAPP: 
    117117            doeslogging = 1 
    118  
    119         if doeslogging: 
    120             stdout_logger = os.path.join(config.FREEVO_LOGDIR, '%s-stdout-%s.log' % (debug_name, os.getuid())) 
    121             try: 
    122                 self.stdout_log = open(stdout_logger, 'w') 
    123             except OSError, why: 
    124                 _debug_('Cannot open "%s": %s' % (stdout_logger, why), DWARNING) 
    125                 self.stdout_log = None 
    126  
    127             stderr_logger = os.path.join(config.FREEVO_LOGDIR, '%s-stderr-%s.log' % (debug_name, os.getuid())) 
    128             try: 
    129                 self.stderr_log = open(stderr_logger, 'w') 
    130             except OSError, why: 
    131                 _debug_('Cannot open "%s": %s' % (stderr_logger, why), DWARNING) 
    132                 self.stderr_log = None 
    133         else: 
    134             self.stdout_log = None 
    135             self.stderr_log = None 
    136118 
    137119        command_isstr = isinstance(command, str) 
     
    157139            return 
    158140 
    159         self.so = Read_Thread('stdout', self.child.stdout, self.stdout_cb, debug_name, doeslogging, callback_use_rc) 
     141        self.so = Read_Thread('stdout', self.child.stdout, self.stdout_cb, app_name, doeslogging, callback_use_rc) 
    160142        self.so.setDaemon(1) 
    161143        self.so.start() 
    162144 
    163         self.se = Read_Thread('stderr', self.child.stderr, self.stderr_cb, debug_name, doeslogging, callback_use_rc) 
     145        self.se = Read_Thread('stderr', self.child.stderr, self.stderr_cb, app_name, doeslogging, callback_use_rc) 
    164146        self.se.setDaemon(1) 
    165147        self.se.start() 
     
    238220                _debug_('killed %s the easy way, status %s' % (self.child.pid, self.status)) 
    239221                if not self.child.stdin.closed: self.child.stdin.close() 
    240                 if self.stdout_log: self.stdout_log.close() 
    241                 if self.stderr_log: self.stderr_log.close() 
    242222                self.child = None 
    243223                return 
     
    301281            self.lock.release() 
    302282        if not self.child.stdin.closed: self.child.stdin.close() 
    303         if self.stdout_log: self.stdout_log.close() 
    304         if self.stderr_log: self.stderr_log.close() 
    305283        self.child = None 
    306284 
     
    391369    Thread for reading stdout or stderr from the child 
    392370    """ 
    393     def __init__(self, name, fh, callback, logger=None, doeslogging=0, callback_use_rc=True): 
     371    def __init__(self, name, fh, callback, appname=None, doeslogging=0, callback_use_rc=True): 
    394372        """ 
    395373        Constructor of Read_Thread 
    396374        """ 
    397         _debug_('Read_Thread.__init__(name=%r, fh=%r, callback=%r, logger=%r, doeslogging=%r' % \ 
    398             (name, fh, callback, logger, doeslogging), 2) 
     375        _debug_('Read_Thread.__init__(name=%r, fh=%r, callback=%r, appname=%r, doeslogging=%r, callback_use_rc=%r)' % \ 
     376            (name, fh, callback, appname, doeslogging, callback_use_rc), 2) 
    399377        threading.Thread.__init__(self) 
    400378        self.name = name 
     
    403381        self.callback_use_rc = callback_use_rc 
    404382        self.logger = None 
    405         if logger and doeslogging: 
    406             logfile = os.path.join(config.FREEVO_LOGDIR, '%s-%s-%s.log' % (logger, name, os.getuid())) 
     383        if appname and doeslogging: 
     384            t = time.strftime('%s') 
     385            logfile = os.path.join(config.FREEVO_LOGDIR, '%s-%s-%s-%s.log' % (appname, name, os.getuid(), t)) 
    407386            try: 
    408387                try: