Changeset 368

Show
Ignore:
Timestamp:
06/18/2001 07:14:29 AM (8 years ago)
Author:
chris
Message:

Main thread will now also exit if please_die Event is set. This allows
other threads to signal that the program should exit.

The console server thread will not be started if CONSPORT=0. This allows
the console feature to be disabled if required.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • eddie/trunk/bin/eddie.py

    r361 r368  
    1 #!/usr/local/bin/python 
    2 ##  
     1#!/opt/python2/bin/python 
     2## 
    33## File         : eddie.py  
    44##  
     
    9898config.loadExtraDirectives(os.path.join(commonlibdir, "Directives")) 
    9999 
    100 # Start Stop the Main threads 
     100 
    101101def start_threads(sargs, cargs): 
    102     global sthread 
    103     global cthread 
    104  
    105     please_die.clear() 
     102    """Start any support threads that are required. 
     103    Currently these are: 
     104     - Scheduler thread: schedules directives to run 
     105     - Console Server thread: handles connections to console port 
     106    """ 
     107 
     108    please_die.clear()          # reset thread signal 
     109 
     110    global sthread              # the Scheduler thread 
    106111    sthread = threading.Thread(group=None, target=scheduler, name='Scheduler', args=sargs, kwargs={}) 
    107     sthread.start() # start it up 
    108  
    109     cthread = threading.Thread(group=None, target=sockets.console_server_thread, name='Console', args=cargs, kwargs={}) 
    110     cthread.start() 
     112    sthread.start()             # start the thread running 
     113 
     114    global cthread              # the Console Server thread 
     115    if config.consport > 0:     # don't start if CONSPORT=0 
     116        cthread = threading.Thread(group=None, target=sockets.console_server_thread, name='Console', args=cargs, kwargs={}) 
     117        cthread.start() 
    111118 
    112119    return() 
    113120 
     121 
    114122def stop_threads(): 
    115     please_die.set() 
    116     sthread.join() 
    117     cthread.join() 
     123    """Stop any threads started by start_threads(). 
     124    """ 
     125 
     126    please_die.set()            # signal threads to die 
     127 
     128    sthread.join()              # wait for schedular thread to die 
     129 
     130    if config.consport > 0:     # console thread not running if CONSPORT=0 
     131        cthread.join()          # wait for console thread to die 
    118132 
    119133    return() 
     134 
    120135  
    121 # Exit Eddie cleanly 
    122136def eddieexit(): 
     137    """Exit Eddie cleanly. 
     138    """ 
     139 
    123140    log.log( '<eddie>eddieexit(), Eddie exiting cleanly.', 3 ) 
    124141    # email admin any remaining messages 
     
    404421    start_threads(sargs,cargs) 
    405422 
    406     while 1: 
     423    while not please_die.isSet(): 
    407424        try: 
    408425            ### Perform housecleaning duties 
     
    441458            log.sendadminlog() 
    442459 
    443             time.sleep(10*60)   # sleep for 10 minutes between housekeeping duties 
     460            #time.sleep(10*60)  # sleep for 10 minutes between housekeeping duties 
     461            please_die.wait(10*60)      # sleep for 10 minutes between housekeeping duties 
     462                                        # or until all threads signalled to exit 
    444463 
    445464        except KeyboardInterrupt: 
     
    447466            log.log( '<eddie>main(), KeyboardInterrupt encountered - quitting', 1 ) 
    448467            print "\nEddie quitting ... bye bye" 
    449             break 
    450  
    451  
    452     # Save history (debug.. FS only for now...) 
    453     #history.eddieHistory.save('FS',directive.dlist) 
    454  
    455     # sleep for set period - only quits with CTRL-c 
    456     #log.log( '<eddie>main(), sleeping for %d secs' % (config.scanperiod), 6 ) 
    457  
    458     # Sleep by setting SIGALRM to go off in scanperiod seconds 
    459     #time.sleep( config.scanperiod ) 
    460     #signal.alarm( config.scanperiod ) 
    461     #signal.pause() 
     468            eddieexit() 
     469 
     470 
     471    log.log( '<eddie>main(), main thread signalled to die - exiting', 1 ) 
     472    eddieexit() 
     473 
    462474 
    463475