示例#1
0
    def close(self):
        if not self._channel.closed:
            data = self._data.getvalue()
            l = len(data)
            DebugLogger.log('A', id(self._channel),
                            '%s %s' % (self._channel.reply_code, l))
            self._channel.push('%010d%s%010d' % (l, data, 0), 0)
            self._channel.push(
                LoggingProducer(self._channel, l, 'log_request'), 0)
            self._channel.push(
                CallbackProducer(lambda t=('E', id(self._channel)): apply(
                    DebugLogger.log, t)), 0)

            if self._shutdown:
                try:
                    r = self._shutdown[0]
                except:
                    r = 0
                config.ZSERVER_EXIT_CODE = r
                self._channel.push(ShutdownProducer(), 0)
                Wakeup(lambda: asyncore.close_all())
            else:
                self._channel.push(None, 0)
                Wakeup()
        self._data = None
        self._channel = None
示例#2
0
    def _finish(self):
        self.channel.reply_code = self.status

        DebugLogger.log('A', id(self.channel),
                        '%d %d' % (self.status, self.stdout.length))

        t = self._tempfile
        if t is not None:
            self.stdout.write((file_close_producer(t), 0))
        self._tempfile = None

        self.channel.sendStreamTerminator(FCGI_STDOUT)
        self.channel.sendEndRecord()
        self.stdout.close()
        self.stderr.close()

        if not self.channel.closed:
            self.channel.push_with_producer(
                LoggingProducer(self.channel, self.stdout.length,
                                'log_request'), 0)
        if self._shutdownRequested():
            config.ZSERVER_EXIT_CODE = self._shutdown_flag
            self.channel.push(ShutdownProducer(), 0)
            Wakeup(lambda: asyncore.close_all())
        else:
            self.channel.push(None, 0)
            Wakeup()
        self.channel = None
示例#3
0
    def close(self):
        log('A', id(self._request),
            '%s %s' % (self._request.reply_code, self._bytes))
        if not self._channel.closed:
            self._channel.push(LoggingProducer(self._request, self._bytes), 0)
            self._channel.push(CallbackProducer(self._channel.done), 0)
            self._channel.push(
                CallbackProducer(lambda t=
                                 ('E', id(self._request)): apply(log, t)), 0)
            if self._shutdown:
                self._channel.push(ShutdownProducer(), 0)
                Wakeup()
            else:
                if self._close: self._channel.push(None, 0)
            Wakeup()
        else:
            # channel closed too soon

            self._request.log(self._bytes)
            log('E', id(self._request))

            if self._shutdown:
                Wakeup(lambda: asyncore.close_all())
            else:
                Wakeup()

        self._channel = None  #need to break cycles?
        self._request = None
示例#4
0
 def write(self, text, l=None):
     if self._channel.closed:
         return
     if l is None: l = len(text)
     self._bytes = self._bytes + l
     self._channel.push(text, 0)
     Wakeup()
示例#5
0
    def done(self):
        # Read status line from output
        status_line = self.output.split('\r\n').pop(0)

        # Acknowledge done task for queue with expected consumer state
        task_queue = self.server.get_task_queue()

        # Acquire lock when not the main thread
        try:
            if self.server.ident != threading.currentThread().ident:
                self.server.unfinished_tasks_mutex.acquire()

            self.server.unfinished_tasks -= 1
            task_queue.task_done(self.task,
                                 status_line=status_line,
                                 consumer_name=self.server.name,
                                 consumer_length=self.server.unfinished_tasks)

        finally:
            # Release lock when not the main thread
            if self.server.ident != threading.currentThread().ident:
                self.server.unfinished_tasks_mutex.release()

        # Signal that mutex is free and queue can be polled again
        Wakeup()

        # Log warning when HTTP 3xx
        if status_line.startswith('HTTP/1.1 3'):
            pos = self.output.find('Location: ')
            location = self.output[max(0, pos):].split('\r\n').pop(0)
            logger.warning('{0:s} ({1:s} --> {2:s} [not followed])'.format(
                status_line, self.task['url'], location[10:]))

        # Log error when not HTTP 2xx
        elif not status_line.startswith('HTTP/1.1 2'):
            logger.error('{0:s} ({1:s})'.format(status_line, self.task['url']))
示例#6
0
 def release(self):
     with self._mutex:
         if self._deferred is not None:
             self._push(*self._deferred)
         self._released = True
     Wakeup()