# HG changeset patch # User Thierry Florac # Date 1541761904 -3600 # Node ID 514949952033ed7fc63332260caec437e8128c94 # Parent 70d8305004c376a053340c04766cb8e5f16ce9c1 Check if medias converter port is available before starting process to avoid zombies diff -r 70d8305004c3 -r 514949952033 src/pyams_media/include.py --- a/src/pyams_media/include.py Fri Nov 09 12:01:44 2018 +0100 +++ b/src/pyams_media/include.py Fri Nov 09 12:11:44 2018 +0100 @@ -29,6 +29,7 @@ # import packages from pyams_media.process import MediaConversionProcess, MediaConversionMessageHandler +from pyams_utils.protocol.tcp import is_port_in_use from pyams_utils.registry import set_local_registry, get_global_registry from pyams_utils.zodb import get_connection_from_settings from pyams_zmq.process import process_exit_func @@ -56,14 +57,20 @@ """Start converter process when application created""" # check for PyAMS command line script - cmsline = os.path.split(sys.argv[0])[-1] - if cmsline.startswith('pyams_'): + cmdline = os.path.split(sys.argv[0])[-1] + if cmdline.startswith('pyams_'): return registry = get_global_registry() settings = registry.settings start_handler = asbool(settings.get(CONVERTER_STARTER_KEY, False)) if start_handler: + # check if port is available + handler_address = settings.get(CONVERTER_HANDLER_KEY, '127.0.0.1:5556') + hostname, port = handler_address.split(':') + if is_port_in_use(int(port), hostname): + logger.info("Medias converter port already used, aborting...") + return # get database connection connection = get_connection_from_settings(settings) root = connection.root() @@ -78,7 +85,7 @@ conversion_util = sm.get(CONVERTER_NAME) if conversion_util is not None: # create medias converter process - process = MediaConversionProcess(settings.get(CONVERTER_HANDLER_KEY, '127.0.0.1:5556'), + process = MediaConversionProcess(handler_address, MediaConversionMessageHandler, settings.get(CONVERTER_AUTH_KEY), settings.get(CONVERTER_CLIENTS_KEY),