Centralize cooperative yield

Replace the remaining time.sleep calls use to trigger eventlet yield
to the existing nova.utils.cooperative_yield() call. This will help
us to disable such yielding in when the service is running in threading
mode and eventually drop the whole thing when nova removes eventlet.

Change-Id: I6b3fcba13f4d1c41d1fac2efe3cb4a943e66f8bb
Signed-off-by: Balazs Gibizer <gibi@redhat.com>
This commit is contained in:
Balazs Gibizer
2025-05-27 15:05:53 +02:00
parent f8b72e964c
commit 858494997e
3 changed files with 4 additions and 6 deletions

View File

@@ -19,7 +19,6 @@ Manage hosts in the current zone.
import collections
import functools
import time
import iso8601
from oslo_log import log as logging
@@ -465,8 +464,7 @@ class HostManager(object):
"updated": False}
inst_dict = self._instance_info[host]
inst_dict["instances"][instance.uuid] = instance
# Call sleep() to cooperatively yield
time.sleep(0)
utils.cooperative_yield()
LOG.debug("END:_async_init_instance_info")
# Run this async so that we don't block the scheduler start-up

View File

@@ -16,13 +16,13 @@
import os
import tempfile
import time
from unittest import mock
import eventlet
import fixtures
from nova import test
from nova import utils
from nova.virt.disk.mount import nbd
from nova.virt.image import model as imgmodel
@@ -304,7 +304,7 @@ class NbdTestCase(test.NoDBTestCase):
# Ensure that context switch happens before the device is marked
# as used. This will cause a failure without nbd-allocation-lock
# in place.
time.sleep(0.1)
utils.cooperative_yield()
# We always choose the top device in find_unused - remove it now.
free_devices.pop()

View File

@@ -11537,7 +11537,7 @@ class LibvirtDriver(driver.ComputeDriver):
future.add_done_callback(thread_finished)
# Let eventlet schedule the new thread right away
time.sleep(0)
utils.cooperative_yield()
try:
LOG.debug("Starting monitoring of live migration",