Beispiel #1
0
 def _sigHup(self, sigNum, frame):
     # do not process overlapped signals
     if not self.signalMutex.acquire(0): return
     try:
         self.logReopen()
     except Exception, x:
         logException(1)
         log(1, 'SIGHUP handler: exception: %s' % x)
Beispiel #2
0
 def _shutdown(self, sigNum, frame):
     # do not process overlapped signals
     if not self.signalMutex.acquire(False): return
     try:
         shutdown.set()
     except Exception, x:
         logException(1)
         log(1, 'signal handler: exception: %s' % x)
Beispiel #3
0
 def start( self ):
   log(2, 'starting "%s"' % self.cmd)
   try:
     self.proc = subprocess.Popen(
       self.cmd, shell=True, bufsize=0,
       stdin=subprocess.PIPE, stdout=subprocess.PIPE,
       stderr=subprocess.PIPE, close_fds=True)
     self.out = BindOutput(self.name, self.proc.stdout, self._output, (), self._finished)
     self.err = BindOutput(self.name, self.proc.stderr, self._error)
   except:
     logException(1)
def store_component(path, value, svr):
    client=_get_memcache_client()
    if not client:
        return AE.Cache._disk_store(path, value, svr)
    fullpath=C.memcachePathPrefix+path
    pickled=cPickle.dumps(value, cPickle.HIGHEST_PROTOCOL)
    exp_time=value.get('exp_time', 0)
    try:
        res=client.set(fullpath, pickled, exp_time)
    except:
        ERROR("exception storing component at path %s" % fullpath)
        logException()
def store_component(path, value, svr):
    client = _get_memcache_client()
    if not client:
        return AE.Cache._disk_store(path, value, svr)
    fullpath = C.memcachePathPrefix + path
    pickled = cPickle.dumps(value, cPickle.HIGHEST_PROTOCOL)
    exp_time = value.get('exp_time', 0)
    try:
        res = client.set(fullpath, pickled, exp_time)
    except:
        ERROR("exception storing component at path %s" % fullpath)
        logException()
Beispiel #6
0
 def send_request(self):
     headers = {"Connection": "Keep-Alive", "Accept": "text/html"}
     try:
         self.conn.request("GET",
                           HTTPKeepAliveConnection.DEFAULT_REQUEST,
                           headers=headers)
         response = self.conn.getresponse()
         if response.status != 200:
             log(3, "Connection#%d got unexpected status %d (%s)" % \
                 (self.num, response.status, response.reason))
             shutdown.set()
             return False
         response.read()
         return True
     except:
         log(3, "Connection#%d got error" % self.num)
         logException(1)
         shutdown.set()
         return False
Beispiel #7
0
    def _run(self):
        signal.signal(signal.SIGINT, self._shutdown)
        signal.signal(signal.SIGTERM, self._shutdown)
        signal.signal(signal.SIGHUP, self._sigHup)

        if not self._init():
            shutdown.set()
            return

        try:
            self.start()
            log(2, 'Server is started')
            self.main()
            log(5, 'Stopping server...')
        except:
            logException(1)
            log(
                1,
                'Server is stopped due to the following reason: internal error'
            )
            shutdown.set()
        self.stop()
        log(2, 'Server is stopped.')
        self.removePid()
Beispiel #8
0
 def _run( self ):
   try:
     while 1:
       line = self.file.readline()
       if not line:
         if self.finishFn:
           try:
             apply(self.finishFn, self.finArgs)
           except:
             logException(1)
         break
       if line[-1] == '\n': line = line[:-1]
       try:
         apply(self.fn, (line,) + self.fnArgs)
       except:
         logException(1)
   except:
     logException(1)
Beispiel #9
0
    def relativePath(self, dir, *args):
        if len(args) == 1 and not args[0]: return args[0]
        if args and args[0][0] in ['/', '.']:  # it is absolute path
            return os.path.join(*args)
        return os.path.join(*(dir, ) + args)

    def init(self):
        pass

    def _init(self):
        try:
            self.init()
        except ShuttingDown, x:
            return False
        except:
            logException(1)
            log(1, 'Error starting server: internal error')
            return False
        self.writePid()
        return True

    def start(self):
        pass

    def _run(self):
        signal.signal(signal.SIGINT, self._shutdown)
        signal.signal(signal.SIGTERM, self._shutdown)
        signal.signal(signal.SIGHUP, self._sigHup)

        if not self._init():
            shutdown.set()
Beispiel #10
0
 def failed( self ):
   logException(1)
   log(1, 'thread failed')
   shutdown.set()