Make eventlet monkey patching conform to best practices
Per [1], eventlet monkey patching should happen as early as possible to avoid mismatches where a module was imported both before and after it was monkey patched. This is an exception to the import order rules that should maybe be more explicitly called out. In addition, partial monkey patching can be a problem, as shown in the discussion of the thread module from the same document. This seems to be contributing to the doc build problems that are occurring with the latest version of openstackdocstheme, so the partial monkey patching is also removed in favor of full patching. Change-Id: I0d2d9fb9f0b9d747ad1d955420f6ad129ebbfbcf 1: http://specs.openstack.org/openstack/openstack-specs/specs/eventlet-best-practices.html#monkey-patching Closes-Bug: 1759935
This commit is contained in:
parent
ca51cb8465
commit
6310052486
|
@ -20,23 +20,19 @@
|
|||
"""
|
||||
Glance API Server
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
|
||||
# Monkey patch socket, time, select, threads
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch(all=False, socket=True, time=True,
|
||||
select=True, thread=True, os=True)
|
||||
eventlet.patcher.monkey_patch()
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
# If ../glance/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
|
|
|
@ -20,21 +20,20 @@
|
|||
"""
|
||||
Reference implementation server for Glance Registry
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
# Monkey patch socket and time
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch(all=False, socket=True, time=True, thread=True)
|
||||
eventlet.patcher.monkey_patch()
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
# If ../glance/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
"""
|
||||
Glance Scrub Service
|
||||
"""
|
||||
import eventlet
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch()
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
@ -29,7 +37,6 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
|||
os.pardir))
|
||||
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
import eventlet
|
||||
|
||||
import glance_store
|
||||
from oslo_config import cfg
|
||||
|
@ -38,14 +45,6 @@ from oslo_log import log as logging
|
|||
from glance.common import config
|
||||
from glance import scrubber
|
||||
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch(all=False, socket=True, time=True, select=True,
|
||||
thread=True, os=True)
|
||||
|
||||
CONF = cfg.CONF
|
||||
logging.register_options(CONF)
|
||||
|
|
|
@ -13,6 +13,15 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch()
|
||||
|
||||
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
||||
# The code below enables tests to work with i18n _() blocks
|
||||
import six.moves.builtins as __builtin__
|
||||
|
@ -26,12 +35,3 @@ formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
|||
hdlr.setFormatter(formatter)
|
||||
logger.addHandler(hdlr)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
import eventlet
|
||||
# NOTE(jokke): As per the eventlet commit
|
||||
# b756447bab51046dfc6f1e0e299cc997ab343701 there's circular import happening
|
||||
# which can be solved making sure the hubs are properly and fully imported
|
||||
# before calling monkey_patch(). This is solved in eventlet 0.22.0 but we
|
||||
# need to address it before that is widely used around.
|
||||
eventlet.hubs.get_hub()
|
||||
eventlet.patcher.monkey_patch()
|
||||
|
|
Loading…
Reference in New Issue