Prevent calling "monkey_patch" more than once

This patch is adding a check to prevent calling
``eventlet.monkey_patch()`` more than once per execution.

This patch is also preventing any import before this method has been
called. Any import is moved after that.

Closes-Bug: #2091538
Topic: eventlet-deprecation
Change-Id: I675aaf124d6630b6827febb1e5a5f492ed874107
This commit is contained in:
Rodolfo Alonso Hernandez 2024-12-11 10:08:36 +00:00
parent 83de306105
commit bedb19bb22

View File

@ -14,11 +14,18 @@
# under the License.
import eventlet
from oslo_utils import importutils
IS_MONKEY_PATCHED = False
def monkey_patch():
eventlet.monkey_patch()
global IS_MONKEY_PATCHED
if not IS_MONKEY_PATCHED:
eventlet.monkey_patch()
p_c_e = importutils.import_module('pyroute2.config.asyncio')
p_c_e.asyncio_config()
# pylint: disable=import-outside-toplevel
from oslo_utils import importutils
p_c_e = importutils.import_module('pyroute2.config.asyncio')
p_c_e.asyncio_config()
IS_MONKEY_PATCHED = True