parameters: (port=DEFAULT_LOGGING_CONFIG_PORT)
return_statement: return threading.Thread(target=serve,
                              args=(ConfigSocketReceiver,
                                    ConfigStreamHandler, port))
docstring: Start up a socket server on the specified port, and listen for new
      configurations.
  
      These will be sent as a file suitable for processing by fileConfig().
      Returns a Thread object on which you can call start() to start the server,
      and which you can join() when appropriate. To stop the server, call
      stopListening().
docstring_summary: Start up a socket server on the specified port, and listen for new
      configurations.
docstring_tokens: Start up a socket server on the specified port and listen for new configurations .
function: def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
      """
      Start up a socket server on the specified port, and listen for new
      configurations.
  
      These will be sent as a file suitable for processing by fileConfig().
      Returns a Thread object on which you can call start() to start the server,
      and which you can join() when appropriate. To stop the server, call
      stopListening().
      """
      if not thread:
          raise NotImplementedError, "listen() needs threading to work"
  
      class ConfigStreamHandler(StreamRequestHandler):
          """
          Handler for a logging configuration request.
  
          It expects a completely new logging configuration and uses fileConfig
          to install it.
          """
          def handle(self):
              """
              Handle a request.
  
              Each request is expected to be a 4-byte length, packed using
              struct.pack(">L", n), followed by the config file.
              Uses fileConfig() to do the grunt work.
              """
              import tempfile
              try:
                  conn = self.connection
                  chunk = conn.recv(4)
                  if len(chunk) == 4:
                      slen = struct.unpack(">L", chunk)[0]
                      chunk = self.connection.recv(slen)
                      while len(chunk) < slen:
                          chunk = chunk + conn.recv(slen - len(chunk))
                      #Apply new configuration. We'd like to be able to
                      #create a StringIO and pass that in, but unfortunately
                      #1.5.2 ConfigParser does not support reading file
                      #objects, only actual files. So we create a temporary
                      #file and remove it later.
                      file = tempfile.mktemp(".ini")
                      f = open(file, "w")
                      f.write(chunk)
                      f.close()
                      try:
                          fileConfig(file)
                      except (KeyboardInterrupt, SystemExit):
                          raise
                      except:
                          traceback.print_exc()
                      os.remove(file)
              except socket.error, e:
                  if type(e.args) != types.TupleType:
                      raise
                  else:
                      errcode = e.args[0]
                      if errcode != RESET_ERROR:
                          raise
  
      class ConfigSocketReceiver(ThreadingTCPServer):
          """
          A simple TCP socket-based logging config receiver.
          """
  
          allow_reuse_address = 1
  
          def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT,
                       handler=None):
              ThreadingTCPServer.__init__(self, (host, port), handler)
              logging._acquireLock()
              self.abort = 0
              logging._releaseLock()
              self.timeout = 1
  
          def serve_until_stopped(self):
              import select
              abort = 0
              while not abort:
                  rd, wr, ex = select.select([self.socket.fileno()],
                                             [], [],
                                             self.timeout)
                  if rd:
                      self.handle_request()
                  logging._acquireLock()
                  abort = self.abort
                  logging._releaseLock()
  
      def serve(rcvr, hdlr, port):
          server = rcvr(port=port, handler=hdlr)
          global _listener
          logging._acquireLock()
          _listener = server
          logging._releaseLock()
          server.serve_until_stopped()
  
      return threading.Thread(target=serve,
                              args=(ConfigSocketReceiver,
                                    ConfigStreamHandler, port))
function_tokens: def listen ( port = DEFAULT_LOGGING_CONFIG_PORT ) : if not thread : raise NotImplementedError , "listen() needs threading to work" class ConfigStreamHandler ( StreamRequestHandler ) : """
          Handler for a logging configuration request.
  
          It expects a completely new logging configuration and uses fileConfig
          to install it.
          """ def handle ( self ) : """
              Handle a request.
  
              Each request is expected to be a 4-byte length, packed using
              struct.pack(">L", n), followed by the config file.
              Uses fileConfig() to do the grunt work.
              """ import tempfile try : conn = self . connection chunk = conn . recv ( 4 ) if len ( chunk ) == 4 : slen = struct . unpack ( ">L" , chunk ) [ 0 ] chunk = self . connection . recv ( slen ) while len ( chunk ) < slen : chunk = chunk + conn . recv ( slen - len ( chunk ) ) #Apply new configuration. We'd like to be able to #create a StringIO and pass that in, but unfortunately #1.5.2 ConfigParser does not support reading file #objects, only actual files. So we create a temporary #file and remove it later. file = tempfile . mktemp ( ".ini" ) f = open ( file , "w" ) f . write ( chunk ) f . close ( ) try : fileConfig ( file ) except ( KeyboardInterrupt , SystemExit ) : raise except : traceback . print_exc ( ) os . remove ( file ) except socket . error , e : if type ( e . args ) != types . TupleType : raise else : errcode = e . args [ 0 ] if errcode != RESET_ERROR : raise class ConfigSocketReceiver ( ThreadingTCPServer ) : """
          A simple TCP socket-based logging config receiver.
          """ allow_reuse_address = 1 def __init__ ( self , host = 'localhost' , port = DEFAULT_LOGGING_CONFIG_PORT , handler = None ) : ThreadingTCPServer . __init__ ( self , ( host , port ) , handler ) logging . _acquireLock ( ) self . abort = 0 logging . _releaseLock ( ) self . timeout = 1 def serve_until_stopped ( self ) : import select abort = 0 while not abort : rd , wr , ex = select . select ( [ self . socket . fileno ( ) ] , [ ] , [ ] , self . timeout ) if rd : self . handle_request ( ) logging . _acquireLock ( ) abort = self . abort logging . _releaseLock ( ) def serve ( rcvr , hdlr , port ) : server = rcvr ( port = port , handler = hdlr ) global _listener logging . _acquireLock ( ) _listener = server logging . _releaseLock ( ) server . serve_until_stopped ( ) return threading . Thread ( target = serve , args = ( ConfigSocketReceiver , ConfigStreamHandler , port ) )