Пример #1
0
  def start(self):
    MAX_TIMEOUT = 10 
    self._running = True
    # Record which thread this loop is running on. The Server Socket can check this
    # to decide what to do.
    self._running_thread = threading.current_thread()
    _poll_time = 1
    _poll = self._poller.poll
    socket = self._socket 
    
    if self.profiler is not None:
      self.profiler.enable()
    
    while self._running:
      socks = dict(_poll())
      if len(socks) == 0:
        _poll_time = min(_poll_time * 2, MAX_TIMEOUT)
      else:
        _poll_time = 1 

      for fd, event in socks.iteritems():
        if fd == self._pipe[0]:
          os.read(fd, 10000)
          continue
        
        if event & zmq.POLLIN: 
          socket.handle_read()
        if event & zmq.POLLOUT: 
          socket.handle_write()
      self._poller.register(socket.zmq(), self._direction)
    
    # Close serversocket after the loop ends.
    self._socket.close()
Пример #2
0
  def _run(self):
    self._running = True
    _poll = self._poller.poll
    _poll_time = 1
    MAX_TIMEOUT = 100

    while self._running:
      socks = dict(_poll(_poll_time))
      
      if len(socks) == 0:
        _poll_time = min(_poll_time * 2, MAX_TIMEOUT)
      else:
        _poll_time = 1

      #util.log_info('%s', self._sockets)
      for fd, event in socks.iteritems():
        if fd == self._pipe[0]:
          os.read(fd, 1)
          continue

        if not fd in self._sockets:
          continue

        socket = self._sockets[fd]
        if event & zmq.POLLIN:
          socket.handle_read(socket)
        if event & zmq.POLLOUT:
          socket.handle_write()
      
      with self._lock:
        for s, dir in self._to_add:
          self._sockets[s.zmq()] = s
          self._poller.register(s.zmq(), dir)
          
        for s, dir in self._to_mod:
          self._poller.register(s.zmq(), dir)

        for s in self._to_del:
          del self._sockets[s.zmq()]
          self._poller.unregister(s.zmq())
        
        del self._to_mod[:]
        del self._to_add[:]
        del self._to_del[:]

        for socket in self._closing.keys():
          socket.handle_close()
        self._closing.clear()
      
      self._epoch += 1
Пример #3
0
    def _run(self):
        self._running = True
        _poll = self._poller.poll
        _poll_time = 1
        MAX_TIMEOUT = 100

        while self._running:
            socks = dict(_poll(_poll_time))

            if len(socks) == 0:
                _poll_time = min(_poll_time * 2, MAX_TIMEOUT)
            else:
                _poll_time = 1

            #util.log_info('%s', self._sockets)
            for fd, event in socks.iteritems():
                if fd == self._pipe[0]:
                    os.read(fd, 1)
                    continue

                if not fd in self._sockets:
                    continue

                socket = self._sockets[fd]
                if event & zmq.POLLIN:
                    socket.handle_read(socket)
                if event & zmq.POLLOUT:
                    socket.handle_write()

            with self._lock:
                for s, dir in self._to_add:
                    self._sockets[s.zmq()] = s
                    self._poller.register(s.zmq(), dir)

                for s, dir in self._to_mod:
                    self._poller.register(s.zmq(), dir)

                for s in self._to_del:
                    del self._sockets[s.zmq()]
                    self._poller.unregister(s.zmq())

                del self._to_mod[:]
                del self._to_add[:]
                del self._to_del[:]

                for socket in self._closing.keys():
                    socket.handle_close()
                self._closing.clear()

            self._epoch += 1