Esempio n. 1
0
 def poll(self, fd, read=False, write=False, exc=False, timeout=None):
     """Suspend the current task until an IO event occurs."""
     expires = None if timeout is None else time.time() + timeout
     if hasattr(fd, 'fileno'):
         fd = fd.fileno()
     wait = FDWait(greenlet.getcurrent(), fd, read, write, exc, expires)
     self.fdwaits.add(wait)
     if timeout is not None:
         self._add_timeout(wait)
     self.greenlet.switch()
Esempio n. 2
0
 def _wait_for_pop(self, timeout):
     """Suspend the current task until a pop happens.
     
     Call this if appending to a full Queue.
     """
     expires = None if timeout is None else time.time() + timeout
     wait = PopWait(greenlet.getcurrent(), self, expires)
     if timeout is not None:
         self.hub._add_timeout(wait)
     self._pop_waits.append(wait)
     self.hub.run()
Esempio n. 3
0
 def _wait_for_append(self, timeout):
     """Suspend the current task until an append happens.
     
     Call this if popping from an empty Queue.
     """
     expires = None if timeout is None else time.time() + timeout
     wait = AppendWait(greenlet.getcurrent(), self, expires)
     if timeout is not None:
         self.hub._add_timeout(wait)
     self._append_waits.append(wait)
     self.hub.run()
Esempio n. 4
0
 def wait_until_empty(self, timeout=None):
     """Suspend the current task until the Queue is empty.
     
     >>> q = Queue()
     >>> q.wait_until_empty()
     >>> q.append('an item')
     >>> q.wait_until_empty(0)
     Traceback (most recent call last):
         ...
     Timeout
     """
     if not self.queue:
         return
     expires = None if timeout is None else time.time() + timeout
     wait = PopWait(greenlet.getcurrent(), self, expires)
     if timeout is not None:
         self.hub._add_timeout(wait)
     while self.queue:
         self._pop_waits.append(wait)
         self.hub.run()
     self._popped()
Esempio n. 5
0
 def switch(self):
     """Reschedule the current task, and run the event-loop."""
     self.schedule(greenlet.getcurrent())
     self.greenlet.switch()
Esempio n. 6
0
 def sleep(self, timeout):
     """Suspend the current task for the specified number of seconds."""
     expires = time.time() + timeout
     sleep = Sleep(greenlet.getcurrent(), expires)
     self._add_timeout(sleep)
     self.greenlet.switch()