Esempio n. 1
0
 def __init__ (self):
   Task.__init__(self)
   self.workers = set()
   self.pinger = makePinger()
   # socket.close() must be performed by this Select task -- otherwise
   # we'll end up blocking on socket that doesn't exist.
   self.pending_worker_closes = []
Esempio n. 2
0
 def __init__ (self):
   Task.__init__(self)
   self._workers = set()
   self.pinger = makePinger()
   # socket.open() and socket.close() are performed by this Select task
   # other threads register open() and close() requests by adding lambdas
   # to this thread-safe queue.
   self._pending_commands = Queue.Queue()
Esempio n. 3
0
 def __init__(self):
     Task.__init__(self)
     self._workers = set()
     self.pinger = makePinger()
     # socket.open() and socket.close() are performed by this Select task
     # other threads register open() and close() requests by adding lambdas
     # to this thread-safe queue.
     self._pending_commands = Queue.Queue()
Esempio n. 4
0
class ReadLoop (object):
  """
  Singleton IO Loop

  Serves "clients", which are objects with fileno() and _do_rx() methods.
  You add clients with add() and remove them with remove().
  This class runs a Task which selects on the clients.  When one becomes
  readable, its _do_rx() is called.

  It is intended to be run as a singleton.  A single instance is available
  as ReadLoop.singleton.
  """
  IO_TIMEOUT = 2

  def __init__ (self):
    self._clients = []
    self._started = False
    self._task = None
    core.add_listener(self._handle_GoingDownEvent, weak=True)
    self.running = True

  class _singleton_property (object):
    def __get__ (self, instance, owner):
      if owner._singleton is None:
        owner._singleton = owner()
      return owner._singleton
  _singleton = None
  singleton = _singleton_property()

  def _handle_GoingDownEvent (self, event):
    self.running = False

  def add (self, client):
    #TODO: Should these be weak refs?
    self._clients.append(client)
    self._start()

  def remove (self, client):
    self._clients.remove(client)

  def _start (self):
    if not self._started:
      self._task = Task(target=self._task_proc)
      self._task.start()
      self._started = True

  def _task_proc (self):
    #log.info("%s task starting", type(self).__name__)
    while core.running and self.running:
      rr,ww,xx = yield Select(self._clients, [], [], self.IO_TIMEOUT)
      for client in rr:
        client._do_rx()
Esempio n. 5
0
 def __init__(self):
   IOMaster.__init__(self)
   Task.__init__(self)
Esempio n. 6
0
 def __init__(self):
     IOMaster.__init__(self)
     Task.__init__(self)
Esempio n. 7
0
 def _start (self):
   if not self._started:
     self._task = Task(target=self._task_proc)
     self._task.start()
     self._started = True