Fix big performance overhead in python runner wrapper script by moving
some very expensive imports inline so they are not imported by functions
inside that module which don't need that functionality.
# See the License for the specific language governing permissions and
# limitations under the License.
-import eventlet
-
import logging as stdlib_logging
from oslo_config import cfg
from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER
from st2common import log as logging
-from st2common.runners import base as runners
-from st2common.util import action_db as action_db_utils
-from st2common.content import utils as content_utils
__all__ = [
@@ -99,6 +94,10 @@ def make_read_and_store_stream_func(execution_db, action_db, store_data_func):
This function writes read data into a buffer and stores it in a database.
"""
+ # NOTE: This import has intentionally been moved here to avoid massive performance overhead
+ # (1+ second) for other functions inside this module which don't need to use those imports.
+ import eventlet
+
def read_and_store_stream(stream, buff):
try:
while not stream.closed:
@@ -125,6 +124,12 @@ def make_read_and_store_stream_func(execution_db, action_db, store_data_func):
def invoke_post_run(liveaction_db, action_db=None):
+ # NOTE: This import has intentionally been moved here to avoid massive performance overhead
+ # (1+ second) for other functions inside this module which don't need to use those imports.
+ from st2common.runners import base as runners
+ from st2common.util import action_db as action_db_utils
+ from st2common.content import utils as content_utils
+
LOG.info('Invoking post run for action execution %s.', liveaction_db.id)
# Identify action and runner.
