Commit f6bb6009 authored by Jason Madden's avatar Jason Madden

Defer importing gevent.monkey at startup. Fixes #1152

parent 840692b0
......@@ -83,7 +83,10 @@ except AttributeError:
_switchinterval = interval
from gevent._config import config
from gevent.hub import get_hub, iwait, wait
from gevent._hub_local import get_hub
from gevent._hub_primitives import iwait_on_objects as iwait
from gevent._hub_primitives import wait_on_objects as wait
from gevent.greenlet import Greenlet, joinall, killall
joinall = joinall # export for pylint
spawn = Greenlet.spawn
......
......@@ -8,7 +8,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from gevent.monkey import get_original
from gevent._compat import thread_mod_name
__all__ = [
......@@ -19,7 +19,9 @@ __all__ = [
# These must be the "real" native thread versions,
# not monkey-patched.
class _Threadlocal(get_original(thread_mod_name, '_local')):
# We are imported early enough (by gevent/__init__) that
# we can rely on not being monkey-patched in any way yet.
class _Threadlocal(__import__(thread_mod_name)._local):
def __init__(self):
# Use a class with an initializer so that we can test
......
......@@ -19,8 +19,8 @@ from gevent._tblib import load_traceback
from gevent.exceptions import InvalidSwitchError
from gevent.hub import iwait
from gevent.hub import wait
from gevent._hub_primitives import iwait_on_objects as iwait
from gevent._hub_primitives import wait_on_objects as wait
from gevent.timeout import Timeout
......
......@@ -53,13 +53,14 @@ from gevent import _hub_primitives
wait = _hub_primitives.wait_on_objects
iwait = _hub_primitives.iwait_on_objects
from gevent.monkey import get_original
from gevent.exceptions import LoopExit
from gevent._waiter import Waiter
get_thread_ident = get_original(thread_mod_name, 'get_ident')
# Need the real get_ident. We're imported early enough (by gevent/__init__.py)
# that we can be sure nothing is monkey patched yet.
get_thread_ident = __import__(thread_mod_name).get_ident
MAIN_THREAD_IDENT = get_thread_ident() # XXX: Assuming import is done on the main thread.
......
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