def kill(greenlet, exception=GreenletExit, block=True, polling_period=0.2): """Kill greenlet with exception (GreenletExit by default). Wait for it to die if block is true. """ if not greenlet.dead: waiter = Waiter() core.active_event(_kill, greenlet, exception, waiter) if block: waiter.wait() join(greenlet, polling_period=polling_period)
def kill(self, exception=GreenletExit, block=False, timeout=None): """Raise the exception in the greenlet. If block is ``False`` (the default), the current greenlet is not unscheduled. If block is ``True``, wait until the greenlet dies or the optional timeout expires. Return ``None``. """ if not self.dead: waiter = Waiter() core.active_event(_kill, self, exception, waiter) if block: waiter.wait() self.join(timeout)
def killall(greenlets, exception=GreenletExit, block=True, polling_period=0.2): """Kill all the greenlets with exception (GreenletExit by default). Wait for them to die if block is true. """ waiter = Waiter() core.active_event(_killall, greenlets, exception, waiter) if block: alive = waiter.wait() if alive: joinall(alive, polling_period=polling_period)
def kill(self, exception=GreenletExit, block=True, timeout=None): """Raise the exception in the greenlet. If block is ``True`` (the default), wait until the greenlet dies or the optional timeout expires. If block is ``False``, the current greenlet is not unscheduled. The function always returns ``None`` and never raises an error. `Changed in version 0.13.0:` *block* is now ``True`` by default. """ if self._start_event is not None: self._start_event.cancel() self._start_event = None if not self.dead: waiter = Waiter() core.active_event(_kill, self, exception, waiter) if block: waiter.wait() self.join(timeout)
def kill(self, exception=GreenletExit, block=True, timeout=None): """Raise the exception in the greenlet. If block is ``True`` (the default), wait until the greenlet dies or the optional timeout expires. If block is ``False``, the current greenlet is not unscheduled. The function always returns ``None`` and never raises an errir. `Changed in version 0.13.0:` *block* is now ``True`` by default. """ if self._start_event is not None: self._start_event.cancel() self._start_event = None if not self.dead: waiter = Waiter() core.active_event(_kill, self, exception, waiter) if block: waiter.wait() self.join(timeout)
def killall(greenlets, exception=GreenletExit, block=False, timeout=None): if block: waiter = Waiter() core.active_event(_killall3, greenlets, exception, waiter) if block: t = Timeout.start_new(timeout) try: alive = waiter.wait() if alive: joinall(alive, raise_error=False) finally: t.cancel() else: core.active_event(_killall, greenlets, exception)
def get(self, block=True, timeout=None): """Remove and return an item from the queue. If optional args *block* is true and *timeout* is ``None`` (the default), block if necessary until an item is available. If *timeout* is a positive number, it blocks at most *timeout* seconds and raises the :class:`Empty` exception if no item was available within that time. Otherwise (*block* is false), return an item if one is immediately available, else raise the :class:`Empty` exception (*timeout* is ignored in that case). """ if self.qsize(): if self.putters: self._schedule_unlock() return self._get() elif not block and get_hub() is getcurrent(): # special case to make get_nowait() runnable in the mainloop greenlet # there are no items in the queue; try to fix the situation by unlocking putters while self.putters: putter = self.putters.pop() if putter: putter.switch(putter) if self.qsize(): return self._get() raise Empty elif block: waiter = Waiter() timeout = Timeout.start_new(timeout, Empty) try: self.getters.add(waiter) if self.putters: self._schedule_unlock() return waiter.wait() finally: self.getters.discard(waiter) timeout.cancel() else: raise Empty