Commit 870e8e13 authored by Jason Madden's avatar Jason Madden

Greenlet can cimport waiter.

parent cdac6316
......@@ -3,10 +3,12 @@
cimport cython
from gevent.__ident cimport IdentRegistry
from gevent.__hub_local cimport get_hub_noargs as get_hub
cdef bint _greenlet_imported
from gevent.__waiter cimport Waiter
cdef bint _PYPY
cdef sys_getframe
cdef sys_exc_info
cdef Timeout
cdef extern from "greenlet/greenlet.h":
......@@ -19,9 +21,12 @@ cdef extern from "greenlet/greenlet.h":
greenlet PyGreenlet_GetCurrent()
void PyGreenlet_Import()
@cython.final
cdef inline greenlet getcurrent():
return PyGreenlet_GetCurrent()
cdef bint _greenlet_imported
cdef inline void greenlet_init():
global _greenlet_imported
if not _greenlet_imported:
......
......@@ -17,7 +17,6 @@ from gevent._tblib import load_traceback
from gevent.hub import GreenletExit
from gevent.hub import InvalidSwitchError
from gevent.hub import Waiter
from gevent.hub import iwait
from gevent.hub import wait
......@@ -27,6 +26,8 @@ from gevent._config import config as GEVENT_CONFIG
from gevent._util import Lazy
from gevent._util import readproperty
from gevent._hub_local import get_hub_noargs as get_hub
from gevent import _waiter
__all__ = [
'Greenlet',
......@@ -35,14 +36,13 @@ __all__ = [
]
# In Cython, we define these as 'cdef inline' functions. The
# compilation unit cannot have a direct assignment to them (import
# is assignment) without generating a 'lvalue is not valid target'
# error.
locals()['getcurrent'] = __import__('greenlet').getcurrent
locals()['greenlet_init'] = lambda: None
locals()['Waiter'] = _waiter.Waiter
if _PYPY:
......@@ -638,7 +638,7 @@ class Greenlet(greenlet):
if self.dead:
self.__handle_death_before_start((exception,))
else:
waiter = Waiter() if block else None
waiter = Waiter() if block else None # pylint:disable=undefined-variable
self.parent.loop.run_callback(_kill, self, exception, waiter)
if block:
waiter.get()
......@@ -955,7 +955,7 @@ def killall(greenlets, exception=GreenletExit, block=True, timeout=None):
return
loop = greenlets[0].loop
if block:
waiter = Waiter()
waiter = Waiter() # pylint:disable=undefined-variable
loop.run_callback(_killall3, greenlets, exception, waiter)
t = Timeout._start_new_or_dummy(timeout)
try:
......
......@@ -162,7 +162,7 @@ def sleep(seconds=0, ref=True):
hub = _get_hub_noargs()
loop = hub.loop
if seconds <= 0:
waiter = Waiter()
waiter = Waiter(hub)
loop.run_callback(waiter.switch)
waiter.get()
else:
......@@ -672,7 +672,7 @@ class Hub(TrackedRawGreenlet):
if self.dead:
return True
waiter = Waiter()
waiter = Waiter(self)
if timeout is not None:
timeout = self.loop.timer(timeout, ref=False)
......@@ -782,16 +782,17 @@ def iwait(objects, timeout=None, count=None):
in between items yielded by this function.
"""
# QQQ would be nice to support iterable here that can be generated slowly (why?)
hub = _get_hub_noargs()
if objects is None:
yield _get_hub_noargs().join(timeout=timeout)
yield hub.join(timeout=timeout)
return
count = len(objects) if count is None else min(count, len(objects))
waiter = _MultipleWaiter()
waiter = _MultipleWaiter(hub)
switch = waiter.switch
if timeout is not None:
timer = _get_hub_noargs().loop.timer(timeout, priority=-1)
timer = hub.loop.timer(timeout, priority=-1)
timer.start(switch, _NONE)
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment